Skip to content

Instantly share code, notes, and snippets.

@agocke
Created March 30, 2016 06:24
Show Gist options
  • Save agocke/3f9d4befd2877867e66308dc336534fe to your computer and use it in GitHub Desktop.
Save agocke/3f9d4befd2877867e66308dc336534fe to your computer and use it in GitHub Desktop.
static extern void MyPInvoke(IntPtr ptrToCstr)
static void Main()
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
try
{
MyPInvoke(ptr);
IntPtr cstrPtr = Marshal.PtrToStructure(ptr, typeof(IntPtr))
string myStr = (string)Marshal.PtrToStringAnsi(cstrPtr)
}
finally
{
Marshal.DeallocHGlobal(ptr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment