As long as all of the structure parameters are value types you can just cast
the a pointer of managed structure to a pointer of the same unmanaged
structure, e.g.:
void GetUnmanagedLayout(IN ManagedStruct *pms, OUT UnmanagedStruct &ums)
{
ManagedStruct __pin* pPtr = pms;
memcpy(&ums, (PBYTE)pPtr, sizeof(ums));
OR
ums = *(UnmanagedStruct*)pPtr;
}
make sure to verify the compiler byte alignment ( #pragma pack... )
However, when the structure contain properties other then value types ( such
as arrays ) the memory layout of the managed struct will be different from
the layout of the same unmanaged struct ( as managed arrays are resembled by
'classes' rather then direct heap/stack pointers ) so direct conversion could
not be done, rather the struct to be accessed through unmanaged code could be
exposed through COMInterop ( which will impose a development time increase ).
Hope this helps...
Nadav
http://www.ddevel.com