Win32Hid: Fixing boolean bug and improving value caps union.
1.1 --- a/Win32Hid.cs Sun Feb 15 12:22:43 2015 +0100
1.2 +++ b/Win32Hid.cs Sun Feb 15 13:30:54 2015 +0100
1.3 @@ -243,6 +243,7 @@
1.4
1.5 /// BOOLEAN->BYTE->unsigned char
1.6 [FieldOffset(3)]
1.7 + [MarshalAsAttribute(UnmanagedType.U1)]
1.8 public bool IsAlias;
1.9
1.10 /// USHORT->unsigned short
1.11 @@ -263,18 +264,22 @@
1.12
1.13 /// BOOLEAN->BYTE->unsigned char
1.14 [FieldOffset(12)]
1.15 + [MarshalAsAttribute(UnmanagedType.U1)]
1.16 public bool IsRange;
1.17
1.18 /// BOOLEAN->BYTE->unsigned char
1.19 [FieldOffset(13)]
1.20 + [MarshalAsAttribute(UnmanagedType.U1)]
1.21 public bool IsStringRange;
1.22
1.23 /// BOOLEAN->BYTE->unsigned char
1.24 [FieldOffset(14)]
1.25 + [MarshalAsAttribute(UnmanagedType.U1)]
1.26 public bool IsDesignatorRange;
1.27
1.28 /// BOOLEAN->BYTE->unsigned char
1.29 [FieldOffset(15)]
1.30 + [MarshalAsAttribute(UnmanagedType.U1)]
1.31 public bool IsAbsolute;
1.32
1.33 /// ULONG[10]
1.34 @@ -354,93 +359,125 @@
1.35 public ushort Reserved4;
1.36 }
1.37
1.38 - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)]
1.39 - public struct HIDP_VALUE_CAPS_UNION
1.40 - {
1.41
1.42 - ///
1.43 - [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
1.44 - public HIDP_VALUE_CAPS_RANGE Range;
1.45 -
1.46 - ///
1.47 - [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
1.48 - public HIDP_VALUE_CAPS_NOT_RANGE NotRange;
1.49 - }
1.50 -
1.51 - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
1.52 + /// <summary>
1.53 + ///
1.54 + /// </summary>
1.55 + [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
1.56 public struct HIDP_VALUE_CAPS
1.57 {
1.58
1.59 /// USAGE->USHORT->unsigned short
1.60 + [FieldOffset(0)]
1.61 public ushort UsagePage;
1.62
1.63 /// UCHAR->unsigned char
1.64 + [FieldOffset(2)]
1.65 public byte ReportID;
1.66
1.67 /// BOOLEAN->BYTE->unsigned char
1.68 - public byte IsAlias;
1.69 + [FieldOffset(3)]
1.70 + [MarshalAsAttribute(UnmanagedType.U1)]
1.71 + public bool IsAlias;
1.72
1.73 /// USHORT->unsigned short
1.74 + [FieldOffset(4)]
1.75 public ushort BitField;
1.76
1.77 /// USHORT->unsigned short
1.78 + [FieldOffset(6)]
1.79 public ushort LinkCollection;
1.80
1.81 /// USAGE->USHORT->unsigned short
1.82 + [FieldOffset(8)]
1.83 public ushort LinkUsage;
1.84
1.85 /// USAGE->USHORT->unsigned short
1.86 + [FieldOffset(10)]
1.87 public ushort LinkUsagePage;
1.88
1.89 /// BOOLEAN->BYTE->unsigned char
1.90 - public byte IsRange;
1.91 + [FieldOffset(12)]
1.92 + [MarshalAsAttribute(UnmanagedType.U1)]
1.93 + public bool IsRange;
1.94
1.95 /// BOOLEAN->BYTE->unsigned char
1.96 - public byte IsStringRange;
1.97 + [FieldOffset(13)]
1.98 + [MarshalAsAttribute(UnmanagedType.U1)]
1.99 + public bool IsStringRange;
1.100
1.101 /// BOOLEAN->BYTE->unsigned char
1.102 - public byte IsDesignatorRange;
1.103 + [FieldOffset(14)]
1.104 + [MarshalAsAttribute(UnmanagedType.U1)]
1.105 + public bool IsDesignatorRange;
1.106
1.107 /// BOOLEAN->BYTE->unsigned char
1.108 - public byte IsAbsolute;
1.109 + [FieldOffset(15)]
1.110 + [MarshalAsAttribute(UnmanagedType.U1)]
1.111 + public bool IsAbsolute;
1.112
1.113 /// BOOLEAN->BYTE->unsigned char
1.114 - public byte HasNull;
1.115 + [FieldOffset(16)]
1.116 + [MarshalAsAttribute(UnmanagedType.U1)]
1.117 + public bool HasNull;
1.118
1.119 /// UCHAR->unsigned char
1.120 + [FieldOffset(17)]
1.121 public byte Reserved;
1.122
1.123 /// USHORT->unsigned short
1.124 + [FieldOffset(18)]
1.125 public ushort BitSize;
1.126
1.127 /// USHORT->unsigned short
1.128 + [FieldOffset(20)]
1.129 public ushort ReportCount;
1.130
1.131 /// USHORT[5]
1.132 - [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 5, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)]
1.133 - public ushort[] Reserved2;
1.134 + /// We had to use 5 ushorts instead of an array to avoid alignment exception issues.
1.135 + [FieldOffset(22)]
1.136 + public ushort Reserved21;
1.137 + [FieldOffset(24)]
1.138 + public ushort Reserved22;
1.139 + [FieldOffset(26)]
1.140 + public ushort Reserved23;
1.141 + [FieldOffset(28)]
1.142 + public ushort Reserved24;
1.143 + [FieldOffset(30)]
1.144 + public ushort Reserved25;
1.145
1.146 /// ULONG->unsigned int
1.147 + [FieldOffset(32)]
1.148 public uint UnitsExp;
1.149
1.150 /// ULONG->unsigned int
1.151 + [FieldOffset(36)]
1.152 public uint Units;
1.153
1.154 /// LONG->int
1.155 + [FieldOffset(40)]
1.156 public int LogicalMin;
1.157
1.158 /// LONG->int
1.159 + [FieldOffset(44)]
1.160 public int LogicalMax;
1.161
1.162 /// LONG->int
1.163 + [FieldOffset(48)]
1.164 public int PhysicalMin;
1.165
1.166 /// LONG->int
1.167 + [FieldOffset(52)]
1.168 public int PhysicalMax;
1.169
1.170 - ///
1.171 - public HIDP_VALUE_CAPS_UNION Union;
1.172 + /// Union Range/NotRange
1.173 + [FieldOffset(56)]
1.174 + public HIDP_VALUE_CAPS_RANGE Range;
1.175 +
1.176 + [FieldOffset(56)]
1.177 + public HIDP_VALUE_CAPS_NOT_RANGE NotRange;
1.178 }
1.179 +
1.180 }
1.181
1.182