How to convert a structure including an array into a byte stream / array?

O

ORC

How to convert a structure that contains arrays and strings into a byte
stream/array using C# in both Full Framework and in Compact Framework???
In C++ above is very easy but as far as I understand it isn't that easy in
C# because arrays aren't actually "included" in the structure - only as a
"pointer". But how would one save large structures to e.g. a file or send
them through a serial port and vice versa? - Any good idea that will work in
both Full Framework and in Compact Framework? (I'll have to interface to an
existing file stream so I'm not able to change the format of the structure
layout).

Thanks - any help is really highly appreciated!
Ole
 
O

ORC

Thanks Alex,

I have downloaded the CustomMarshaler from opennetcf and have read the
article but I'm afraid that I'm a too newbie to fully understand what's
going on in there. Instead I will try to explain my need and hope that
anybody will be able to help me or give me a hint.

I'll receive a byte array from a serial port. The byte array is actually a
serialized structure with an alignment of 4. The structure is originally
written in C++ and looks e.g. like this:
struct Parameters
{
double CreatedDate;
byte Initials[13];
double TempSensorOffset;
double TempSensorSlope;
double MathReverseCoef[3][3];
double MathForwardCoef[3][3];
double StrainsOffset[3];
double StrainsSlope[3];
};

In C++ I just created a Union of the structure and a byte array and then I
have directly access to both withhout having to do any kind of conversion.
How should I do this in C# using e.g. the CustomMarshaler (I need to both
send and receive from and to the structure)? Does the Marshaller work in
both full and compact framework?

Thanks a lot!
Ole
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top