Renaming demo application to HID Demo.
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 HidStatus 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("hid.dll", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
35 public static extern HidStatus HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] 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("hid.dll", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
43 public static extern HidStatus HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] HIDP_VALUE_CAPS[] ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData);
45 /// Return Type: NTSTATUS->LONG->int
46 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
47 ///UsagePage: USAGE->USHORT->unsigned short
48 ///LinkCollection: USHORT->unsigned short
49 ///Usage: USAGE->USHORT->unsigned short
50 ///UsageValue: PULONG->ULONG*
51 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
52 ///Report: PCHAR->CHAR*
53 ///ReportLength: ULONG->unsigned int
54 [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetUsageValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
55 public static extern HidStatus HidP_GetUsageValue(HIDP_REPORT_TYPE ReportType, ushort UsagePage, ushort LinkCollection, ushort Usage, ref uint UsageValue, System.IntPtr PreparsedData, [MarshalAs(UnmanagedType.LPArray)] byte[] Report, uint ReportLength);
62 static partial class Macro
69 static partial class Const
76 public enum HIDP_REPORT_TYPE : ushort
84 public enum HidStatus : uint
86 HIDP_STATUS_SUCCESS = 0x110000,
87 HIDP_STATUS_NULL = 0x80110001,
88 HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001,
89 HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002,
90 HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003,
91 HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004,
92 HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005,
93 HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006,
94 HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007,
95 HIDP_STATUS_INTERNAL_ERROR = 0xc0110008,
96 HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009,
97 HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a,
98 HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b,
99 HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c,
100 HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d,
101 HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e,
102 HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f,
103 HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010,
104 HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020,
105 HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009
109 [StructLayout(LayoutKind.Sequential)]
110 public struct USAGE_AND_PAGE
113 public ushort UsagePage;
116 [StructLayout(LayoutKind.Sequential)]
117 public struct HIDD_ATTRIBUTES
120 public ushort VendorID;
121 public ushort ProductID;
122 public ushort VersionNumber;
126 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
127 public struct HIDP_CAPS
129 /// USAGE->USHORT->unsigned short
132 /// USAGE->USHORT->unsigned short
133 public ushort UsagePage;
135 /// USHORT->unsigned short
136 public ushort InputReportByteLength;
138 /// USHORT->unsigned short
139 public ushort OutputReportByteLength;
141 /// USHORT->unsigned short
142 public ushort FeatureReportByteLength;
145 [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 17, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)]
146 public ushort[] Reserved;
148 /// USHORT->unsigned short
149 public ushort NumberLinkCollectionNodes;
151 /// USHORT->unsigned short
152 public ushort NumberInputButtonCaps;
154 /// USHORT->unsigned short
155 public ushort NumberInputValueCaps;
157 /// USHORT->unsigned short
158 public ushort NumberInputDataIndices;
160 /// USHORT->unsigned short
161 public ushort NumberOutputButtonCaps;
163 /// USHORT->unsigned short
164 public ushort NumberOutputValueCaps;
166 /// USHORT->unsigned short
167 public ushort NumberOutputDataIndices;
169 /// USHORT->unsigned short
170 public ushort NumberFeatureButtonCaps;
172 /// USHORT->unsigned short
173 public ushort NumberFeatureValueCaps;
175 /// USHORT->unsigned short
176 public ushort NumberFeatureDataIndices;
180 /// Type created in place of an anonymous struct
182 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
183 public struct HIDP_BUTTON_CAPS_RANGE
186 /// USAGE->USHORT->unsigned short
187 public ushort UsageMin;
189 /// USAGE->USHORT->unsigned short
190 public ushort UsageMax;
192 /// USHORT->unsigned short
193 public ushort StringMin;
195 /// USHORT->unsigned short
196 public ushort StringMax;
198 /// USHORT->unsigned short
199 public ushort DesignatorMin;
201 /// USHORT->unsigned short
202 public ushort DesignatorMax;
204 /// USHORT->unsigned short
205 public ushort DataIndexMin;
207 /// USHORT->unsigned short
208 public ushort DataIndexMax;
212 /// Type created in place of an anonymous struct
214 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
215 public struct HIDP_BUTTON_CAPS_NOT_RANGE
218 /// USAGE->USHORT->unsigned short
221 /// USAGE->USHORT->unsigned short
222 public ushort Reserved1;
224 /// USHORT->unsigned short
225 public ushort StringIndex;
227 /// USHORT->unsigned short
228 public ushort Reserved2;
230 /// USHORT->unsigned short
231 public ushort DesignatorIndex;
233 /// USHORT->unsigned short
234 public ushort Reserved3;
236 /// USHORT->unsigned short
237 public ushort DataIndex;
239 /// USHORT->unsigned short
240 public ushort Reserved4;
246 [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
247 public struct HIDP_BUTTON_CAPS
249 /// USAGE->USHORT->unsigned short
251 public ushort UsagePage;
253 /// UCHAR->unsigned char
255 public byte ReportID;
257 /// BOOLEAN->BYTE->unsigned char
259 [MarshalAsAttribute(UnmanagedType.U1)]
262 /// USHORT->unsigned short
264 public ushort BitField;
266 /// USHORT->unsigned short
268 public ushort LinkCollection;
270 /// USAGE->USHORT->unsigned short
272 public ushort LinkUsage;
274 /// USAGE->USHORT->unsigned short
276 public ushort LinkUsagePage;
278 /// BOOLEAN->BYTE->unsigned char
280 [MarshalAsAttribute(UnmanagedType.U1)]
283 /// BOOLEAN->BYTE->unsigned char
285 [MarshalAsAttribute(UnmanagedType.U1)]
286 public bool IsStringRange;
288 /// BOOLEAN->BYTE->unsigned char
290 [MarshalAsAttribute(UnmanagedType.U1)]
291 public bool IsDesignatorRange;
293 /// BOOLEAN->BYTE->unsigned char
295 [MarshalAsAttribute(UnmanagedType.U1)]
296 public bool IsAbsolute;
300 [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.U4)]
301 public uint[] Reserved;
303 /// Union Range/NotRange
305 public HIDP_BUTTON_CAPS_RANGE Range;
308 public HIDP_BUTTON_CAPS_NOT_RANGE NotRange;
312 /// Type created in place of an anonymous struct
314 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
315 public struct HIDP_VALUE_CAPS_RANGE
318 /// USAGE->USHORT->unsigned short
319 public ushort UsageMin;
321 /// USAGE->USHORT->unsigned short
322 public ushort UsageMax;
324 /// USHORT->unsigned short
325 public ushort StringMin;
327 /// USHORT->unsigned short
328 public ushort StringMax;
330 /// USHORT->unsigned short
331 public ushort DesignatorMin;
333 /// USHORT->unsigned short
334 public ushort DesignatorMax;
336 /// USHORT->unsigned short
337 public ushort DataIndexMin;
339 /// USHORT->unsigned short
340 public ushort DataIndexMax;
344 /// Type created in place of an anonymous struct
346 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
347 public struct HIDP_VALUE_CAPS_NOT_RANGE
350 /// USAGE->USHORT->unsigned short
353 /// USAGE->USHORT->unsigned short
354 public ushort Reserved1;
356 /// USHORT->unsigned short
357 public ushort StringIndex;
359 /// USHORT->unsigned short
360 public ushort Reserved2;
362 /// USHORT->unsigned short
363 public ushort DesignatorIndex;
365 /// USHORT->unsigned short
366 public ushort Reserved3;
368 /// USHORT->unsigned short
369 public ushort DataIndex;
371 /// USHORT->unsigned short
372 public ushort Reserved4;
379 [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
380 public struct HIDP_VALUE_CAPS
383 /// USAGE->USHORT->unsigned short
385 public ushort UsagePage;
387 /// UCHAR->unsigned char
389 public byte ReportID;
391 /// BOOLEAN->BYTE->unsigned char
393 [MarshalAsAttribute(UnmanagedType.U1)]
396 /// USHORT->unsigned short
398 public ushort BitField;
400 /// USHORT->unsigned short
402 public ushort LinkCollection;
404 /// USAGE->USHORT->unsigned short
406 public ushort LinkUsage;
408 /// USAGE->USHORT->unsigned short
410 public ushort LinkUsagePage;
412 /// BOOLEAN->BYTE->unsigned char
414 [MarshalAsAttribute(UnmanagedType.U1)]
417 /// BOOLEAN->BYTE->unsigned char
419 [MarshalAsAttribute(UnmanagedType.U1)]
420 public bool IsStringRange;
422 /// BOOLEAN->BYTE->unsigned char
424 [MarshalAsAttribute(UnmanagedType.U1)]
425 public bool IsDesignatorRange;
427 /// BOOLEAN->BYTE->unsigned char
429 [MarshalAsAttribute(UnmanagedType.U1)]
430 public bool IsAbsolute;
432 /// BOOLEAN->BYTE->unsigned char
434 [MarshalAsAttribute(UnmanagedType.U1)]
437 /// UCHAR->unsigned char
439 public byte Reserved;
441 /// USHORT->unsigned short
443 public ushort BitSize;
445 /// USHORT->unsigned short
447 public ushort ReportCount;
450 /// We had to use 5 ushorts instead of an array to avoid alignment exception issues.
452 public ushort Reserved21;
454 public ushort Reserved22;
456 public ushort Reserved23;
458 public ushort Reserved24;
460 public ushort Reserved25;
462 /// ULONG->unsigned int
464 public uint UnitsExp;
466 /// ULONG->unsigned int
472 public int LogicalMin;
476 public int LogicalMax;
480 public int PhysicalMin;
484 public int PhysicalMax;
486 /// Union Range/NotRange
488 public HIDP_VALUE_CAPS_RANGE Range;
491 public HIDP_VALUE_CAPS_NOT_RANGE NotRange;