How to get byte[] from IntPtr in C#

被刻印的时光 ゝ 提交于 2019-12-02 10:31:27

问题


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:


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


来源:https://stackoverflow.com/questions/5298930/how-to-get-byte-from-intptr-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!