I have a C++ struct below:
struct CUSTOM_DATA {
int id;
u_short port;
unsigned long ip;
} custom_data;
How can i convert it to C#
The C# version of this struct would be:
[StructLayout(LayoutKind.Sequential)]
public struct CustomData
{
public int id;
public ushort port;
public uint ip;
}
As for sending this via a socket, you can just send the binary data directly. The Marshal class has methods for getting a pointer (IntPtr) from the structure and copying into a byte array.
[StructLayout(LayoutKind.Sequential)]
struct CUSTOM_DATA {
int id;
ushort port;
uint ip;
};
CUSTOM_DATA cData ; // use me
edit: thx reed