[Solved] C# pinvoke of C function returning char* [duplicate]
You cannot return a pointer to a local variable since those are allocated on the stack (and the stack may get destroyed when the function returns). You’d need to allocate memory on the heap (preferably using CoTaskMemAlloc so the CLR can free up the memory later) on your C function and return a pointer to … Read more