473,326 Members | 2,133 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,326 software developers and data experts.

(char*)&

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(PAC KET));

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
Nov 15 '05 #1
2 1832
(char*)&Data is the same as IntPtr

"Luca Bart" <lu************@hotmail.com> wrote in message
news:bd*************************@posting.google.co m...
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(PAC KET));

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

Nov 15 '05 #2
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" <pd****@ukr.net> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
(char*)&Data is the same as IntPtr

"Luca Bart" <lu************@hotmail.com> wrote in message
news:bd*************************@posting.google.co m...
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(PAC KET));

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


Nov 15 '05 #3

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

Similar topics

7
by: Alex Vinokur | last post by:
========================================== Windows 2000 Professional CYGWIN_NT-5.0 1.5.4(0.94/3/2) GNU g++ version 3.2 20020927 (prerelease) GNU objdump 2.14.90 20030901...
8
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
3
by: Marcin Kalicinski | last post by:
void f(const char *&text); Is this a const reference to char * or a reference to const char *? And how to write both of them? thank you, Marcin
11
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
2
by: Zorro | last post by:
In header file istream there is an overload for every built-in type, except char. Is there a reason for this? GCC 3.3.4. is the compiler. Thanks.
3
by: gevadas | last post by:
sample program #include <iostream> #include <vector> using namespace std; int find(char*& value,char** arr,int size) { for(int i = 0;i < size;i++)
5
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------ #include <iostream> void g(char&){}; void h(const char&) {}; int main() { char c;
0
by: Medhatithi | last post by:
I have a table whose indexed column is a char(16) field. I am giving the schema. CREATE TABLE Emp(Empno char(16), Ename varchar(25), ...
5
by: Samant.Trupti | last post by:
Hi, There is one thing I am cofused about.... If I have a declareation say char str; Now if I want to change it to wchar so do I have to change it like .... wchar_t str; or double the...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.