C# – How to cast IntPtr to byte*


I'm calling a method via interop that returns an out IntPtr parameter. How can I get a byte* for this IntPtr so I can operate on it? I tried the following:

fixed(byte* ptr = (byte)myIntPtr)

but it didn't work. Any help would be appreciated!

Best Solution

You can simply write:

byte* ptr = (byte*)int_ptr;

You don't have to use the fixed keyword. You don't want to pin the IntPtr, do you?