我在使用此代码时遇到了一些问题:
//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将数据从托管结构“复制”到内存中。这两个地点实际上是一样的吗? pElement指向的托管struct oElement和已分配的内存?