I am trying to use some pinvoke code to call a C function. The function fills a buffer with data.
The structure is set up as a DWORD for the length, followed by a string. How do I extract the string from the IntPtr?
IntPtr buffer = Marshal.AllocHGlobal(nRequiredSize);
PInvokedFunction(buffer, nRequiredSize);
string s = Marshal.PtrToStringAuto(buffer + 4); //this is an error.
Marshal.FreeHGlobal(buffer);