[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto, Size = 68 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)]
struct MIXERCONTROL
{
[FieldOffset(0)] public UInt32 cbStruct;
[FieldOffset(4)] public UInt32 dwControlID;
[FieldOffset(8)] public UInt32 dwControlType;
[FieldOffset(12)] public UInt32 fdwControl;
[FieldOffset(16)] public UInt32 cMultipleItems;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MIXER_SHORT_NAME_CHARS)]
[FieldOffset(20)] public string szShortName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MIXER_LONG_NAME_CHARS)]
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS)]
public string szName;
// Union "Bounds" start
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)]
public UnionBoundsSigned ubs;
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)]
public UnionBoundsUnsigned ubus; //insatnce of UnionBoundsSigned struct
/* [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)]
public UInt32[] dwReserved1;*/
// Union "Bounds" end
// Union "Metrics" start
// additonal 6 DWORDs
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS + 24)]
public UInt32 cSteps;
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS + 24)]
public UInt32 cbCustomData;
/* [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]
[FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS + 24)]
public UInt32[] dwReserved2;*/
// Union "Metrics" end
}
<StructLayout(LayoutKind.Explicit, Size:=68 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Structure MIXERCONTROL
<FieldOffset(0)> Dim cbStruct As UInteger
<FieldOffset(4)> Dim dwControlID As UInteger
<FieldOffset(8)> Dim dwControlType As ControlType
<FieldOffset(12)> Dim fdwControl As UInteger
<FieldOffset(16)> Dim cMultipleItem As UInteger
<FieldOffset(20), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> _
Dim szShortName As String
<FieldOffset(20 + MIXER_SHORT_NAME_CHARS), MarshalAs(UnmanagedType.ByValTStr, sizeConst:=MIXER_LONG_NAME_CHARS)> _
Dim szName As String
'Union "Bounds"
<FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim lMinimum As ULong
<FieldOffset(28 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim lMaximum As ULong
<FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwMinimum As UInteger
<FieldOffset(24 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwMaximum As UInteger
<FieldOffset(20 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved1 As UInteger
<FieldOffset(24 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved2 As UInteger
<FieldOffset(28 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved3 As UInteger
<FieldOffset(32 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved4 As UInteger
<FieldOffset(36 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved5 As UInteger
<FieldOffset(40 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved6 As UInteger
'Union "Metrics"
<FieldOffset(44 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim cSteps As UInteger
<FieldOffset(44 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim cbCustomData As UInteger
<FieldOffset(44 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved7 As UInteger
<FieldOffset(48 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved8 As UInteger
<FieldOffset(52 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved9 As UInteger
<FieldOffset(56 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved10 As UInteger
<FieldOffset(60 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved11 As UInteger
<FieldOffset(64 + MIXER_SHORT_NAME_CHARS + MIXER_LONG_NAME_CHARS)> _
Dim dwReserved12 As UInteger
End Structure
None.
The original structure has a union of two structs and an array. In .NET this kind of union cannot be reproduced because, at runtime, the application crashes, the exception says that it's not possible to put both a numeric type and a class type at the same offset (in this situation, a dwReserved() UInt32 Array and the two UInt32 fields); so we have to replace it with other fields (is possible to force offset leaving "empty space", with no field filling it like in C# implementation?!).