Created
March 30, 2016 06:24
-
-
Save agocke/3f9d4befd2877867e66308dc336534fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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