How can I return a StringBuilder or other string buffer from a PInvoke native callback
问题 I would like a clean way to increase the size of a StringBuilder() as required for population by native code, the callback method below seems clean, but somehow we get a copy of the buffer instead of the actual buffer - I'm interested in explanations and solutions (preferably sticking to the callback type allocation as it would be nice and clean if only it could be made work). using System; using System.Runtime.InteropServices; using System.Text; namespace csharpapp { internal class Program {