У меня проблемы с этим кодом:
//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 «копирует» данные из управляемой структуры в память. Так на самом ли деле два места одинаковы? Управляемая структура oElement и выделенная память, на которые указывает pElement?