问题
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