I am trying to use a structure from a C DLL in a C# application. I can't get the equivalent data types for the structure I am dealing with. I am dealing with these data types from C:
struct teststruct {
unsigned short protocol_type; //c#'s UInt16 ?
unsigned char hardwareSize; //c#'s byte?
UCHAR dest[6]; //unsigned char and thus byte in c#?
unsigned char ip_version : 4; //How to get the exact same thing in c#?!!
unsigned char Nonce_Sum_Flag: 1; //the same as above
unsigned char ip[4]; // !!
unsigned short in6_addr_src[8]; // !!
char* astring; //string!?
char anarray[10]; //string? or char[]?
const char* conststring; //string? or array[] or char[]?
};
For the structure itself I think putting the in advance
[StructLayout(LayoutKind.Sequential)]
suffices.
This is my C# structure; as it is clear, I'm stuck with the middle two and last 3 data types. I have no clue how to go about them!
[StructLayout(LayoutKind.Sequential)]
public struct teststruct
{
public UInt16 protocol_type; //c's unsigned short ?
public byte hardwareSize; //c's unsigned char?
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] dest; //c's unsigned char ?
unsigned char ip_version : 4; //How to get the exact same thing in c#?!!
unsigned char Nonce_Sum_Flag : 1; //the same as above
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] ip; // right?!
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public UInt16[] in6_addr_src; // !!
char* astring; // !?
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public byte[] anarray; //string? or char[]?
const char* conststring; //string? or array[] or char[]?
}
Would someone especially advise me on the C unique notion on bit allocation? I mean this line:
unsigned char Nonce_Sum_Flag: 1;
and also the last 3 ones!