473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Managed -> UnManaged Serialization DeSerialization

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

Nov 16 '05 #1
2 3452
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" <csharp at briankeating.net> wrote in message
news:AE**********************************@microsof t.com...
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


Nov 16 '05 #2
Thanks Dmitriy,
Yes I think i've gotten around it finally (doing just what you suggested)
Thanks for you help.

regards
Brian

"Dmitriy Lapshin [C# / .NET MVP]" wrote:
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" <csharp at briankeating.net> wrote in message
news:AE**********************************@microsof t.com...
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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
I'm at a point where I would really like to focus in on learning .NET but am having a hard time deciding which language to use. I learned to program in C++ but have spent quite a bit of time using...
3
by: Steve Marsden | last post by:
Hi I am an experienced C programmer and we have a large app written in C which I have just recompiled with /clr to start to add in managed code to use .NET framework and windows forms bit by...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
2
by: Bob Altman | last post by:
Hi all, We have a native class modeled after the System::Exception class, and all exceptions that we throw derive from this class. For now this class is quite simple: just Description and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.