diff -r 7ef0f9dc229c -r 89dfad9633b2 Win32Hid.cs --- a/Win32Hid.cs Sun Feb 15 12:22:43 2015 +0100 +++ b/Win32Hid.cs Sun Feb 15 13:30:54 2015 +0100 @@ -243,6 +243,7 @@ /// BOOLEAN->BYTE->unsigned char [FieldOffset(3)] + [MarshalAsAttribute(UnmanagedType.U1)] public bool IsAlias; /// USHORT->unsigned short @@ -263,18 +264,22 @@ /// BOOLEAN->BYTE->unsigned char [FieldOffset(12)] + [MarshalAsAttribute(UnmanagedType.U1)] public bool IsRange; /// BOOLEAN->BYTE->unsigned char [FieldOffset(13)] + [MarshalAsAttribute(UnmanagedType.U1)] public bool IsStringRange; /// BOOLEAN->BYTE->unsigned char [FieldOffset(14)] + [MarshalAsAttribute(UnmanagedType.U1)] public bool IsDesignatorRange; /// BOOLEAN->BYTE->unsigned char [FieldOffset(15)] + [MarshalAsAttribute(UnmanagedType.U1)] public bool IsAbsolute; /// ULONG[10] @@ -354,93 +359,125 @@ public ushort Reserved4; } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)] - public struct HIDP_VALUE_CAPS_UNION - { - /// - [System.Runtime.InteropServices.FieldOffsetAttribute(0)] - public HIDP_VALUE_CAPS_RANGE Range; - - /// - [System.Runtime.InteropServices.FieldOffsetAttribute(0)] - public HIDP_VALUE_CAPS_NOT_RANGE NotRange; - } - - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + /// + /// + /// + [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)] public struct HIDP_VALUE_CAPS { /// USAGE->USHORT->unsigned short + [FieldOffset(0)] public ushort UsagePage; /// UCHAR->unsigned char + [FieldOffset(2)] public byte ReportID; /// BOOLEAN->BYTE->unsigned char - public byte IsAlias; + [FieldOffset(3)] + [MarshalAsAttribute(UnmanagedType.U1)] + public bool IsAlias; /// USHORT->unsigned short + [FieldOffset(4)] public ushort BitField; /// USHORT->unsigned short + [FieldOffset(6)] public ushort LinkCollection; /// USAGE->USHORT->unsigned short + [FieldOffset(8)] public ushort LinkUsage; /// USAGE->USHORT->unsigned short + [FieldOffset(10)] public ushort LinkUsagePage; /// BOOLEAN->BYTE->unsigned char - public byte IsRange; + [FieldOffset(12)] + [MarshalAsAttribute(UnmanagedType.U1)] + public bool IsRange; /// BOOLEAN->BYTE->unsigned char - public byte IsStringRange; + [FieldOffset(13)] + [MarshalAsAttribute(UnmanagedType.U1)] + public bool IsStringRange; /// BOOLEAN->BYTE->unsigned char - public byte IsDesignatorRange; + [FieldOffset(14)] + [MarshalAsAttribute(UnmanagedType.U1)] + public bool IsDesignatorRange; /// BOOLEAN->BYTE->unsigned char - public byte IsAbsolute; + [FieldOffset(15)] + [MarshalAsAttribute(UnmanagedType.U1)] + public bool IsAbsolute; /// BOOLEAN->BYTE->unsigned char - public byte HasNull; + [FieldOffset(16)] + [MarshalAsAttribute(UnmanagedType.U1)] + public bool HasNull; /// UCHAR->unsigned char + [FieldOffset(17)] public byte Reserved; /// USHORT->unsigned short + [FieldOffset(18)] public ushort BitSize; /// USHORT->unsigned short + [FieldOffset(20)] public ushort ReportCount; /// USHORT[5] - [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 5, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)] - public ushort[] Reserved2; + /// We had to use 5 ushorts instead of an array to avoid alignment exception issues. + [FieldOffset(22)] + public ushort Reserved21; + [FieldOffset(24)] + public ushort Reserved22; + [FieldOffset(26)] + public ushort Reserved23; + [FieldOffset(28)] + public ushort Reserved24; + [FieldOffset(30)] + public ushort Reserved25; /// ULONG->unsigned int + [FieldOffset(32)] public uint UnitsExp; /// ULONG->unsigned int + [FieldOffset(36)] public uint Units; /// LONG->int + [FieldOffset(40)] public int LogicalMin; /// LONG->int + [FieldOffset(44)] public int LogicalMax; /// LONG->int + [FieldOffset(48)] public int PhysicalMin; /// LONG->int + [FieldOffset(52)] public int PhysicalMax; - /// - public HIDP_VALUE_CAPS_UNION Union; + /// Union Range/NotRange + [FieldOffset(56)] + public HIDP_VALUE_CAPS_RANGE Range; + + [FieldOffset(56)] + public HIDP_VALUE_CAPS_NOT_RANGE NotRange; } + }