开发者

How to get byte[] from IntPtr in C#

开发者 https://www.devze.com 2023-02-16 13:22 出处:网络
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?

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号