IntPtr to Byte Array and Back

后端 未结 2 835
野的像风
野的像风 2020-12-10 07:29

Referencing How to get IntPtr from byte[] in C#

I am attempting to read the data that an IntPtr is referencing into a byte [] and then back into another IntPtr. The

2条回答
  •  孤街浪徒
    2020-12-10 07:44

    1- I assume bmpptr is already an unmanaged pointer, if so why do you need to 'round-trip' this back to an unmanaged pointer unmanagedPointer?

    2- Marshal.SizeOf will not give you the size of the unmanaged memory allocation.

    Using Marshal.Copy, you can copy the contents of unmanaged memory to a managed byte array, but you will need to know how many bytes need to be moved from the unmanaged buffer to the managed buffer. The API should ideally provide this information.

提交回复
热议问题