I am trying to create the following struct in this msdn article. I am trying to learn the whole FieldOffset but have no clue where to start.
I basically did something like this.
[StructLayout(LayoutKind.Explicit, Size=12)]
public struct DHCP_OPTION_DATA_ELEMENT {
[FieldOffset(0)]
public DHCP_OPTION_DATA_TYPE OptionType;
[FieldOffset(4)]
public byte ByteOption;
[FieldOffset(4)]
public uint WordOption;
[FieldOffset(4)]
public UInt32 DWordOption;
[FieldOffset(4)]
public UInt32 DWordDWordOption;
[FieldOffset(4)]
public uint IpAddressOption;
[FieldOffset(4)]
public IntPtr StringDataOption;
[FieldOffset(4)]
public DHCP_BINARY_DATA BinaryDataOption;
[FieldOffset(4)]
public DHCP_BINARY_DATA EncapsulatedDataOption;
[FieldOffset(4)]
public string Ipv6AddressDataOption;
}
However, it barked at me stating the following exception.
it contains an object field at offset 4 that is incorrectly aligned or
overlapped by a non-object field.