How to get byte[] from IntPtr in C#
I want to pass a IntPtr
to 开发者_C百科a method takes a byte[]
Parameter in c#. Is that possible and if it is possible how can I do that?
thx
Check out the Marshal.Copy
method.
byte[] managedArray = {1,2,3,4,5};
int size = Marshal.SizeOf(managedArray[0]) * managedArray.Length;
IntPtr pnt = Marshal.AllocHGlobal(size);
Marshal.Copy(pnt, managedArray, 0 , managedArray.Length);
精彩评论