Static Byte [] StructTobytes (Object Structobj)
{
INT size = marshal.sizeof (structobj);
INTPTR BUFFER = Marshal.allochglobal (size);
Try
{
Marshal.StructureToptr (structobj, buffer, false);
Byte [] BYTES = New byte [size];
Marshal.copy (Buffer, Bytes, 0, size);
Return Bytes;
}
Finally
{
Marshal.Freehglobal (BUFFER);
}
}
Static Object Bytestostruct (Byte [] Bytes, Type Strcuttype
{
INT size = marshal.sizeof (strcuttype);
INTPTR BUFFER = Marshal.allochglobal (size);
Try
{
Marshal.copy (Bytes, 0, Buffer, Size);
Return Marshal.PTRTOStructure (Buffer, Strcuttype);
}
Finally
{
Marshal.Freehglobal (BUFFER);
}
}