J
Jeffrey B. Holtz
THANK YOU 1,000 fold if anyone can help me in this Marshalling:
C structure
===========
struct mystruct {
char tag;
char field1;
char field2;
char field3;
long field4;
union struct2 tagData;
}
union struct2 {
struct struct3 union1;
struct struct4 union2;
}
struct struct3 {
long id;
char flags;
char size;
char data[MAX_SIZE];
}
struct struct4 {
char byte1;
char byte2;
char byte3;
}
C# Attempt
==========
[StructLayout (LayoutKind.Explicit, Pack=1, CharSet=CharSet.Ansi)]
public struct oldStruct
{
[FieldOffset (0)] public byte tag;
[FieldOffset (1)] public byte field1;
[FieldOffset (2)] public byte field2;
[FieldOffset (3)] public byte field3;
[FieldOffset (4)] public uint field4;
/* union members */
// VRcvMsg
[FieldOffset (8) ] public uint id;
[FieldOffset (12)] public byte flags;
[FieldOffset (13)] public byte dlc;
[FieldOffset (14)] public byte [] data;
// union2
[FieldOffset (8) ] public byte byte1;
[FieldOffset (9) ] public byte byte2;
[FieldOffset (10)] public byte byte3;
}
Although this compiles, It cannot instantiate oldStruct because the
data is not aligned properly. I've thought of just putting MAX_SIZE
data parameters and brute force but.....
THANKS to anyone out there
C structure
===========
struct mystruct {
char tag;
char field1;
char field2;
char field3;
long field4;
union struct2 tagData;
}
union struct2 {
struct struct3 union1;
struct struct4 union2;
}
struct struct3 {
long id;
char flags;
char size;
char data[MAX_SIZE];
}
struct struct4 {
char byte1;
char byte2;
char byte3;
}
C# Attempt
==========
[StructLayout (LayoutKind.Explicit, Pack=1, CharSet=CharSet.Ansi)]
public struct oldStruct
{
[FieldOffset (0)] public byte tag;
[FieldOffset (1)] public byte field1;
[FieldOffset (2)] public byte field2;
[FieldOffset (3)] public byte field3;
[FieldOffset (4)] public uint field4;
/* union members */
// VRcvMsg
[FieldOffset (8) ] public uint id;
[FieldOffset (12)] public byte flags;
[FieldOffset (13)] public byte dlc;
[FieldOffset (14)] public byte [] data;
// union2
[FieldOffset (8) ] public byte byte1;
[FieldOffset (9) ] public byte byte2;
[FieldOffset (10)] public byte byte3;
}
Although this compiles, It cannot instantiate oldStruct because the
data is not aligned properly. I've thought of just putting MAX_SIZE
data parameters and brute force but.....
THANKS to anyone out there