Before parsing the C # struct pointer, you must know how the C # struct is defined. This struct is also defined in C.
C # struct pointer-C # struct definition:
[Structlayout (layoutkind. Sequential)]
Public struct vgastat
{
Public int channelnum; // number of channels
[Financialas (unmanagedtype. byvalarray, sizeconst = 64)]
Public char [] version; // version information
Public uint cpuusage; // CPU usage
Public bool workstatusok; // working status
[Financialas (unmanagedtype. byvalarray, sizeconst = 4)]
Public tagcheckarg [] channelstatistic; // channel information
}
After defining the struct, you can convert the received C # struct pointer to the defined struct object.
Vgastat entries = (vgastat) Marshal. ptrtostructure (iptr, typeof (vgastat ));
// Iptr is the received unmanaged struct pointer.
On the contrary, you can assign values to the struct and mail it to the unmanaged memory.
Assume that VGA is the struct that is instantiated and assigned a value after definition.
Intptr = marshal. allochglobal (marshal. sizeof (VGA ));
Marshal. structuretoptr (VGA, intptr, true );
// Send the intptr pointer to the target party here
Marshal. freehglobal (intptr); // release the allocated unmanaged memory.