Alright, after some work, I've found something that, at the very least,
compiles. Can anyone tell me if this is going to work?
_M_UStruct manStruct = some init value;
System::Object* obj = __box(manStruct);
IntPtr pnt = Marshal::AllocHGlobal(Marshal::SizeOf(obj));
Marshal::StructureToPtr(obj, pnt, true);
functionCall(static_cast<UStruct*>(const_cast<void *>(static_cast<const
void*>(pnt))));
Marshal::FreeHGlobal(pnt);
God, that is so gross looking.
"Lee Crabtree" <lc*******@goisi.com> wrote in message
news:ea*************@TK2MSFTNGP10.phx.gbl...
I have several unmanaged struct types that I've created equivalent managed
struct types for. How do I marshal the managed structs into their
unmanaged versions and vice versa?
Here's a quick example of what I'm working with:
unmanaged C++:
typedef struct _UStruct
{
UCHAR length;
USHORT type;
}UStruct;
and the managed version:
[StructLayout(LayoutKind::Sequential, Pack=1)]
__value public struct _M_UStruct
{
unsigned char length;
unsigned short type;
};
Lee