473,804 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(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((ch ar*)&Data,sizeo f(PACKET),sizeo f(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
Nov 15 '05 #1
2 1871
(char*)&Data is the same as IntPtr

"Luca Bart" <lu************ @hotmail.com> wrote in message
news:bd******** *************** **@posting.goog le.com...
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((ch ar*)&Data,sizeo f(PACKET),sizeo f(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

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.ToByt eArray();

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******** ******@TK2MSFTN GP10.phx.gbl...
(char*)&Data is the same as IntPtr

"Luca Bart" <lu************ @hotmail.com> wrote in message
news:bd******** *************** **@posting.goog le.com...
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((ch ar*)&Data,sizeo f(PACKET),sizeo f(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


Nov 15 '05 #3

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

Similar topics

7
2754
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 ========================================== We can see that the same assembly code is generated for * foo2 (char& )
8
2248
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
3
14527
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
3518
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
2
1684
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
20835
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
2233
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------ #include <iostream> void g(char&){}; void h(const char&) {}; int main() { char c;
0
1354
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), Salary number(10,2),......) Now, there is an index on the Empno field. Now, inside a stored procedure, I am executing a statement select Name=Ename from Emp where Empno=@eno This @eno is varchar(25). So, SQL Server would do the implicit...
5
4750
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 size? like
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10347
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.