The bellow code is a breakdown of the win32 source code. but i get an error
a type loading exception cannot be loaded from an assembly because it contains an object field with an offset of 0 that is incorrectly aligned or is overlapped by a field without an object
there is an S1 structure with elements value-typeand reference-type.. this structure is a member of a union that must have fieldOffset, but all S1 members cannot start with fieldOffset 0, they are a mixture of references and value type ... how can I handle this?
[StructLayout(LayoutKind.Sequential)]
public struct S1
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Const.FieldSizeMsgid + 1)]
public String MsgId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Const.FieldSizeTime + 1)]
public String SendTime;
public UInt32 SubsSeq;
public UInt32 ServTime;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Const.FieldSizeFillerA1 + 1)]
public String Filler;
}
[StructLayout(LayoutKind.Explicit)]
public struct AdminData
{
[FieldOffset(0)] public S1 S11;
[FieldOffset(0)] public S2 S22;
[FieldOffset(0)] public S3 S33;
}
, S1 : , . , AdminData, .
++
typedef struct S1
{
char MsgId [Const.FieldSizeMsgid + 1];
char SendTime[Const.FieldSizeTime + 1];
int SubsSeq;
int ServTime;
char Filler[Const.FieldSizeFillerA1 + 1];
}
union AdminData
{
S1 S11;
S2 S22;
S3 S33;
}
typedef struct MMTPMsg
{
int Length;
short Type;
AdminData Data;
long long TimeStamp;
}