marshaling the System::Guid structure

  • Thread starter Thread starter Lee Crabtree
  • Start date Start date
L

Lee Crabtree

I've been wrapping an unmanaged class, and everything has gone well. That
is...until now.

I've hit a wall while trying to marshal the System::Guid type down into the
unmanaged GUID structure that the unmanaged class asks for. For some
reason, none of my attempts to date have met with success. Maybe someone
else has an idea how this works?

Lee
 
Guid^ g = gcnew Guid ("B6806700-E2B1-4022-9D4B-B0205CB37935");
array<System::Byte>^ a = g->ToByteArray();
_GUID guid;
Marshal::Copy(a, 0, IntPtr(&guid), a->Length);

Note, I'm using VS 2005.

Brian
 
I had to change this some, probably because I'm not using 2005 yet. I wound
up doing this:

char * guidData = static_cast<char*>(const_cast<void*>(static_cast<const
void*>(Marshal::StringToHGlobalAnsi(Convert::ToString(guid.ToByteArray())))));

void __pin *data = &(guidData[0]);

Everything seems to be working. Thanks for the jump-start.

Lee
 
Back
Top