I can’t understand how the method works Copy(IntPtr[], Int32, IntPtr, Int32). I could copy the data contained in several IntPtrs into one IntPtr (as MSDN states), but apparently it does not work as I expected:
IntPtr[] ptrArray = new IntPtr[]
{
Marshal.AllocHGlobal(1),
Marshal.AllocHGlobal(2)
};
Marshal.WriteByte(ptrArray[0], 0, 0xC1);
IntPtr ptr = Marshal.AllocHGlobal(3);
Marshal.Copy(ptrArray, 0, ptr, ptrArray.Length);
byte value = Marshal.ReadByte(ptr, 0);
Does anyone know if I use this method for something that is not its purpose?
source
share