Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast IntPtr to byte*

Tags:

c#

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!

like image 846
Dmitri Nesteruk Avatar asked Apr 03 '09 10:04

Dmitri Nesteruk


2 Answers

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?

like image 119
Jb Evain Avatar answered Oct 13 '22 00:10

Jb Evain


myIntPtr.ToPointer()

like image 23
Noldorin Avatar answered Oct 12 '22 23:10

Noldorin