Now using spaces instead of tabs for indentation.
2 using System.Runtime.InteropServices;
3 using Microsoft.Win32.SafeHandles;
9 static partial class Function
11 [DllImport("hid.dll", CharSet = CharSet.Unicode)]
12 public static extern HidStatus HidP_GetUsagesEx(HIDP_REPORT_TYPE ReportType, ushort LinkCollection, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] USAGE_AND_PAGE[] ButtonList, ref uint UsageLength, IntPtr PreparsedData, [MarshalAs(UnmanagedType.LPArray)] byte[] Report, uint ReportLength);
14 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
15 public static extern Boolean HidD_GetManufacturerString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
17 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
18 public static extern Boolean HidD_GetProductString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
20 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
21 public static extern Boolean HidD_GetAttributes(SafeFileHandle HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
23 /// Return Type: NTSTATUS->LONG->int
24 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
25 ///Capabilities: PHIDP_CAPS->_HIDP_CAPS*
26 [DllImportAttribute("hid.dll", EntryPoint = "HidP_GetCaps", CallingConvention = CallingConvention.StdCall)]
27 public static extern int HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities);
29 /// Return Type: NTSTATUS->LONG->int
30 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
31 ///ButtonCaps: PHIDP_BUTTON_CAPS->_HIDP_BUTTON_CAPS*
32 ///ButtonCapsLength: PUSHORT->USHORT*
33 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
34 [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
35 public static extern int HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_BUTTON_CAPS ButtonCaps, ref ushort ButtonCapsLength, System.IntPtr PreparsedData);
37 /// Return Type: NTSTATUS->LONG->int
38 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
39 ///ValueCaps: PHIDP_VALUE_CAPS->_HIDP_VALUE_CAPS*
40 ///ValueCapsLength: PUSHORT->USHORT*
41 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
42 [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
43 public static extern int HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_VALUE_CAPS ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData);
48 static partial class Macro
55 static partial class Const
62 public enum HIDP_REPORT_TYPE : ushort
70 public enum HidStatus : uint
72 HIDP_STATUS_SUCCESS = 0x110000,
73 HIDP_STATUS_NULL = 0x80110001,
74 HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001,
75 HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002,
76 HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003,
77 HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004,
78 HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005,
79 HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006,
80 HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007,
81 HIDP_STATUS_INTERNAL_ERROR = 0xc0110008,
82 HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009,
83 HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a,
84 HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b,
85 HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c,
86 HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d,
87 HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e,
88 HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f,
89 HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010,
90 HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020,
91 HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009
95 [StructLayout(LayoutKind.Sequential)]
96 public struct USAGE_AND_PAGE
99 public ushort UsagePage;
102 [StructLayout(LayoutKind.Sequential)]
103 public struct HIDD_ATTRIBUTES
106 public ushort VendorID;
107 public ushort ProductID;
108 public ushort VersionNumber;
112 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
113 public struct HIDP_CAPS
116 /// USAGE->USHORT->unsigned short
119 /// USAGE->USHORT->unsigned short
120 public ushort UsagePage;
122 /// USHORT->unsigned short
123 public ushort InputReportByteLength;
125 /// USHORT->unsigned short
126 public ushort OutputReportByteLength;
128 /// USHORT->unsigned short
129 public ushort FeatureReportByteLength;
132 [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 17, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)]
133 public ushort[] Reserved;
135 /// USHORT->unsigned short
136 public ushort NumberLinkCollectionNodes;
138 /// USHORT->unsigned short
139 public ushort NumberInputButtonCaps;
141 /// USHORT->unsigned short
142 public ushort NumberInputValueCaps;
144 /// USHORT->unsigned short
145 public ushort NumberInputDataIndices;
147 /// USHORT->unsigned short
148 public ushort NumberOutputButtonCaps;
150 /// USHORT->unsigned short
151 public ushort NumberOutputValueCaps;
153 /// USHORT->unsigned short
154 public ushort NumberOutputDataIndices;
156 /// USHORT->unsigned short
157 public ushort NumberFeatureButtonCaps;
159 /// USHORT->unsigned short
160 public ushort NumberFeatureValueCaps;
162 /// USHORT->unsigned short
163 public ushort NumberFeatureDataIndices;
167 /// Type created in place of an anonymous struct
169 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
170 public struct HIDP_BUTTON_CAPS_RANGE
173 /// USAGE->USHORT->unsigned short
174 public ushort UsageMin;
176 /// USAGE->USHORT->unsigned short
177 public ushort UsageMax;
179 /// USHORT->unsigned short
180 public ushort StringMin;
182 /// USHORT->unsigned short
183 public ushort StringMax;
185 /// USHORT->unsigned short
186 public ushort DesignatorMin;
188 /// USHORT->unsigned short
189 public ushort DesignatorMax;
191 /// USHORT->unsigned short
192 public ushort DataIndexMin;
194 /// USHORT->unsigned short
195 public ushort DataIndexMax;
199 /// Type created in place of an anonymous struct
201 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
202 public struct HIDP_BUTTON_CAPS_NOT_RANGE
205 /// USAGE->USHORT->unsigned short
208 /// USAGE->USHORT->unsigned short
209 public ushort Reserved1;
211 /// USHORT->unsigned short
212 public ushort StringIndex;
214 /// USHORT->unsigned short
215 public ushort Reserved2;
217 /// USHORT->unsigned short
218 public ushort DesignatorIndex;
220 /// USHORT->unsigned short
221 public ushort Reserved3;
223 /// USHORT->unsigned short
224 public ushort DataIndex;
226 /// USHORT->unsigned short
227 public ushort Reserved4;
230 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)]
231 public struct HIDP_BUTTON_CAPS_UNION
235 [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
236 public HIDP_BUTTON_CAPS_RANGE Range;
239 [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
240 public HIDP_BUTTON_CAPS_NOT_RANGE NotRange;
243 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
244 public struct HIDP_BUTTON_CAPS
247 /// USAGE->USHORT->unsigned short
248 public ushort UsagePage;
250 /// UCHAR->unsigned char
251 public byte ReportID;
253 /// BOOLEAN->BYTE->unsigned char
256 /// USHORT->unsigned short
257 public ushort BitField;
259 /// USHORT->unsigned short
260 public ushort LinkCollection;
262 /// USAGE->USHORT->unsigned short
263 public ushort LinkUsage;
265 /// USAGE->USHORT->unsigned short
266 public ushort LinkUsagePage;
268 /// BOOLEAN->BYTE->unsigned char
271 /// BOOLEAN->BYTE->unsigned char
272 public byte IsStringRange;
274 /// BOOLEAN->BYTE->unsigned char
275 public byte IsDesignatorRange;
277 /// BOOLEAN->BYTE->unsigned char
278 public byte IsAbsolute;
281 [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U4)]
282 public uint[] Reserved;
284 /// TODO: get the proper field offset to make it nicer and get rid of union type
285 public HIDP_BUTTON_CAPS_UNION Union;
289 /// Type created in place of an anonymous struct
291 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
292 public struct HIDP_VALUE_CAPS_RANGE
295 /// USAGE->USHORT->unsigned short
296 public ushort UsageMin;
298 /// USAGE->USHORT->unsigned short
299 public ushort UsageMax;
301 /// USHORT->unsigned short
302 public ushort StringMin;
304 /// USHORT->unsigned short
305 public ushort StringMax;
307 /// USHORT->unsigned short
308 public ushort DesignatorMin;
310 /// USHORT->unsigned short
311 public ushort DesignatorMax;
313 /// USHORT->unsigned short
314 public ushort DataIndexMin;
316 /// USHORT->unsigned short
317 public ushort DataIndexMax;
321 /// Type created in place of an anonymous struct
323 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
324 public struct HIDP_VALUE_CAPS_NOT_RANGE
327 /// USAGE->USHORT->unsigned short
330 /// USAGE->USHORT->unsigned short
331 public ushort Reserved1;
333 /// USHORT->unsigned short
334 public ushort StringIndex;
336 /// USHORT->unsigned short
337 public ushort Reserved2;
339 /// USHORT->unsigned short
340 public ushort DesignatorIndex;
342 /// USHORT->unsigned short
343 public ushort Reserved3;
345 /// USHORT->unsigned short
346 public ushort DataIndex;
348 /// USHORT->unsigned short
349 public ushort Reserved4;
352 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)]
353 public struct HIDP_VALUE_CAPS_UNION
357 [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
358 public HIDP_VALUE_CAPS_RANGE Range;
361 [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
362 public HIDP_VALUE_CAPS_NOT_RANGE NotRange;
365 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
366 public struct HIDP_VALUE_CAPS
369 /// USAGE->USHORT->unsigned short
370 public ushort UsagePage;
372 /// UCHAR->unsigned char
373 public byte ReportID;
375 /// BOOLEAN->BYTE->unsigned char
378 /// USHORT->unsigned short
379 public ushort BitField;
381 /// USHORT->unsigned short
382 public ushort LinkCollection;
384 /// USAGE->USHORT->unsigned short
385 public ushort LinkUsage;
387 /// USAGE->USHORT->unsigned short
388 public ushort LinkUsagePage;
390 /// BOOLEAN->BYTE->unsigned char
393 /// BOOLEAN->BYTE->unsigned char
394 public byte IsStringRange;
396 /// BOOLEAN->BYTE->unsigned char
397 public byte IsDesignatorRange;
399 /// BOOLEAN->BYTE->unsigned char
400 public byte IsAbsolute;
402 /// BOOLEAN->BYTE->unsigned char
405 /// UCHAR->unsigned char
406 public byte Reserved;
408 /// USHORT->unsigned short
409 public ushort BitSize;
411 /// USHORT->unsigned short
412 public ushort ReportCount;
415 [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 5, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)]
416 public ushort[] Reserved2;
418 /// ULONG->unsigned int
419 public uint UnitsExp;
421 /// ULONG->unsigned int
425 public int LogicalMin;
428 public int LogicalMax;
431 public int PhysicalMin;
434 public int PhysicalMax;
437 public HIDP_VALUE_CAPS_UNION Union;