You will probably have to manually "create" a byte structure in C# and put
the data into it since C# and C/C++ have a binary notion of a structure
while C# does not.
What I mean is:
C/C++
struct
{
int a;
char tmp[5];
};
This is formatted in memory something like (not exactly) this: 4 bytes for
the int followed by 5 bytes for the char array.
In C# this is not the same since all of the variables (including the struct
which is now a class) is an object. It is not just a few bytes stored in
memory but instead is a bunch of data and the methods that go with it (aka
an object.)
You will probably have to create a member function in the C# code that will
take all of your member variables and put them into a byte array in the same
order that C/C++ would store them in. You should then be able to send them
over to the C/C++ client and cast it to a struct.
One other thing to keep in mind.. You probably will not be able to just send
your struct only - you will probably want to put a small header onto it that
tells the remote (client/server) how big the packet it. Otherwise if you get
several packets right in a row and perfrom a Recv() and it all in and try to
cast it to a struct it will bomb out.
Hope this helps.
Again, I could be wrong on this so if I am just b-slap me and call me
silly!! :-)
"Abubakar" <ab*******@gmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi,
I am writing a server in C# and client in C++ (pure, not managed). The
communication goes on through sockets. In C# I am using NetworkStream to
send text data (by converting it to byte array) to the c++ client. In c++
client I have "recv" (winsock) function through which I receive
everything.
Now there is a need to pass a "struct" of C# through the "write" function
of
network stream. I want to know how this can be done. Also I would want to
reconstruct the struct at the c++ side after receving data through recv.
Please use a simple struct with few ints to demo this.
Regards,
Ab.