(char*)&

  • Thread starter Thread starter Luca Bart
  • Start date Start date
L

Luca Bart

Dear all,
I have a struct in C++:

typedef struct{
char Command[4];
short a;
}PACKET;

I have to send by UDP and C++ command is:
UDP->SendBuffer((char*)&Data,sizeof(PACKET),sizeof(PACKET));

where data is a PACKET Data=new PACKET; and I put something in that
fields.

What's the C# for (char*)&Data ? I tried to make Data as a Class and
Data.ToString() but I think it's not that.

Thank you very much

Luca
 
Luca,

I just converted a C++ network stream program and ran into the same thing.

The reason they created a union was so that could write the short to the
stream in memory order instead of network order.

The C# way would be:

short shtToSend = 1234;
byte[] abytToSend;

abytToSend = shtToSend.ToByteArray();

If the order needs to be reveresed, I used Array.Reverse() method.

Helpfull hint. I found during the converstion, that many octal, hex and int
values being cast to smaller datatypes. For example "char chOut =
0xFFFFFFF1;". Takes a while to figure out that the original intent was to
set chOut to ebsidic '1'.

All I can say is have fun. :)

Hope this helps.

--
Glen Jones MCSD

Vadym Stetsyak said:
(char*)&Data is the same as IntPtr

Luca Bart said:
Dear all,
I have a struct in C++:

typedef struct{
char Command[4];
short a;
}PACKET;

I have to send by UDP and C++ command is:
UDP->SendBuffer((char*)&Data,sizeof(PACKET),sizeof(PACKET));

where data is a PACKET Data=new PACKET; and I put something in that
fields.

What's the C# for (char*)&Data ? I tried to make Data as a Class and
Data.ToString() but I think it's not that.

Thank you very much

Luca
 
Back
Top