How to get byte[] from IntPtr in C#

2020-04-18 05:59发布

I want to pass a IntPtr to a method takes a byte[] Parameter in c#. Is that possible and if it is possible how can I do that?

thx

1条回答
姐就是有狂的资本
2楼-- · 2020-04-18 07:05

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);
查看更多
登录 后发表回答