Managed -> UnManaged Serialization DeSerialization

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello there,

I wonder can anyone help point me in correct direction.

Basically I have a Managed structure and I want to Serialize to to a byte
array,
Then I want to read this byte array in my <u>UnManaged</u> c++ app and get
the contents.

The reason I nead to serialize the structure is that the Struct is being
sent via a message queue.

My C++ app should then read the message from the queue and be able to read
the contents.

Here is my structure (which i can change)
[StructLayout(LayoutKind.Sequential)]
[Serializable]
public class TraceMonitorMessage
{
public char[] szName = new char[64];
public string strMessage = null;
}

When slightly worried about writing a byte array in C# because it's gonna be
a managed array so i assume it writes a size when it gets binary serialized.
So my C++ app may have to step over this possibly?

I don't know the size of the strMessage in advance.
When i read my message from the Queue in the Unmanaged C++ app I can get the
szName and i know the the rest of the message body i've read is the
strMessage.

Can anyone give me an idea on where to look or how to proceed.
thanks in advance
Brian Keating
 
Hello Brian,

Why not to add a method like GetByteArray() to the structure and implement
your custom 'serialization' within that method?
 
Thanks Dmitriy,
Yes I think i've gotten around it finally (doing just what you suggested)
Thanks for you help.

regards
Brian

Dmitriy Lapshin said:
Hello Brian,

Why not to add a method like GetByteArray() to the structure and implement
your custom 'serialization' within that method?

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Brian Keating said:
Hello there,

I wonder can anyone help point me in correct direction.

Basically I have a Managed structure and I want to Serialize to to a byte
array,
Then I want to read this byte array in my <u>UnManaged</u> c++ app and get
the contents.

The reason I nead to serialize the structure is that the Struct is being
sent via a message queue.

My C++ app should then read the message from the queue and be able to read
the contents.

Here is my structure (which i can change)
[StructLayout(LayoutKind.Sequential)]
[Serializable]
public class TraceMonitorMessage
{
public char[] szName = new char[64];
public string strMessage = null;
}

When slightly worried about writing a byte array in C# because it's gonna
be
a managed array so i assume it writes a size when it gets binary
serialized.
So my C++ app may have to step over this possibly?

I don't know the size of the strMessage in advance.
When i read my message from the Queue in the Unmanaged C++ app I can get
the
szName and i know the the rest of the message body i've read is the
strMessage.

Can anyone give me an idea on where to look or how to proceed.
thanks in advance
Brian Keating
 
Back
Top