このコードに問題があります:
//Creating a new ImageElement Struct
ImageElement oElement = new UM0516.ImageElement();
//Create a pointer and allocate enough room for the struct type
IntPtr pElement = Marshal.AllocHGlobal(Marshal.SizeOf(new UM0516.ImageElement()));
//Copy the contents of the struct into the allocated memory space
Marshal.StructureToPtr(oElement, pElement, true);
//Function that takes a file pointed to by handle, and does some sweet sweet things
//And returns a loaded struct pointed to by pElement
FILES_GetImageElement(handle, el, out pElement);
ここで混乱します。コードをステップ実行して、最後の関数 (pElement が指すメモリ内のビットを変更する必要があります) を呼び出した後、oElement が変更されたことを確認します!? Marshal.StructureToPtr は、管理された構造体からメモリにデータを「コピー」すると思いました。では、2 つの場所は実際には同じでしょうか。管理された構造体 oElement と、pElement が指す割り当てられたメモリ?