Copyright and namespace.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpLibHid.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Runtime.InteropServices;
22 using Microsoft.Win32.SafeHandles;
28 static partial class Function
30 [DllImport("hid.dll", CharSet = CharSet.Unicode)]
31 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);
33 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
34 public static extern Boolean HidD_GetManufacturerString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
36 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
37 public static extern Boolean HidD_GetProductString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
39 [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
40 public static extern Boolean HidD_GetAttributes(SafeFileHandle HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
42 /// Return Type: NTSTATUS->LONG->int
43 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
44 ///Capabilities: PHIDP_CAPS->_HIDP_CAPS*
45 [DllImportAttribute("hid.dll", EntryPoint = "HidP_GetCaps", CallingConvention = CallingConvention.StdCall)]
46 public static extern HidStatus HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities);
48 /// Return Type: NTSTATUS->LONG->int
49 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
50 ///ButtonCaps: PHIDP_BUTTON_CAPS->_HIDP_BUTTON_CAPS*
51 ///ButtonCapsLength: PUSHORT->USHORT*
52 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
53 [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
54 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);
56 /// Return Type: NTSTATUS->LONG->int
57 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
58 ///ValueCaps: PHIDP_VALUE_CAPS->_HIDP_VALUE_CAPS*
59 ///ValueCapsLength: PUSHORT->USHORT*
60 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
61 [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
62 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);
64 /// Return Type: NTSTATUS->LONG->int
65 ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE
66 ///UsagePage: USAGE->USHORT->unsigned short
67 ///LinkCollection: USHORT->unsigned short
68 ///Usage: USAGE->USHORT->unsigned short
69 ///UsageValue: PULONG->ULONG*
70 ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA*
71 ///Report: PCHAR->CHAR*
72 ///ReportLength: ULONG->unsigned int
73 [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetUsageValue", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
74 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);
81 static partial class Macro
88 static partial class Const
95 public enum HIDP_REPORT_TYPE : ushort
103 public enum HidStatus : uint
105 HIDP_STATUS_SUCCESS = 0x110000,
106 HIDP_STATUS_NULL = 0x80110001,
107 HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001,
108 HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002,
109 HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003,
110 HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004,
111 HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005,
112 HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006,
113 HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007,
114 HIDP_STATUS_INTERNAL_ERROR = 0xc0110008,
115 HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009,
116 HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a,
117 HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b,
118 HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c,
119 HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d,
120 HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e,
121 HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f,
122 HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010,
123 HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020,
124 HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009
128 [StructLayout(LayoutKind.Sequential)]
129 public struct USAGE_AND_PAGE
132 public ushort UsagePage;
135 [StructLayout(LayoutKind.Sequential)]
136 public struct HIDD_ATTRIBUTES
139 public ushort VendorID;
140 public ushort ProductID;
141 public ushort VersionNumber;
145 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
146 public struct HIDP_CAPS
148 /// USAGE->USHORT->unsigned short
151 /// USAGE->USHORT->unsigned short
152 public ushort UsagePage;
154 /// USHORT->unsigned short
155 public ushort InputReportByteLength;
157 /// USHORT->unsigned short
158 public ushort OutputReportByteLength;
160 /// USHORT->unsigned short
161 public ushort FeatureReportByteLength;
164 [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 17, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)]
165 public ushort[] Reserved;
167 /// USHORT->unsigned short
168 public ushort NumberLinkCollectionNodes;
170 /// USHORT->unsigned short
171 public ushort NumberInputButtonCaps;
173 /// USHORT->unsigned short
174 public ushort NumberInputValueCaps;
176 /// USHORT->unsigned short
177 public ushort NumberInputDataIndices;
179 /// USHORT->unsigned short
180 public ushort NumberOutputButtonCaps;
182 /// USHORT->unsigned short
183 public ushort NumberOutputValueCaps;
185 /// USHORT->unsigned short
186 public ushort NumberOutputDataIndices;
188 /// USHORT->unsigned short
189 public ushort NumberFeatureButtonCaps;
191 /// USHORT->unsigned short
192 public ushort NumberFeatureValueCaps;
194 /// USHORT->unsigned short
195 public ushort NumberFeatureDataIndices;
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_RANGE
205 /// USAGE->USHORT->unsigned short
206 public ushort UsageMin;
208 /// USAGE->USHORT->unsigned short
209 public ushort UsageMax;
211 /// USHORT->unsigned short
212 public ushort StringMin;
214 /// USHORT->unsigned short
215 public ushort StringMax;
217 /// USHORT->unsigned short
218 public ushort DesignatorMin;
220 /// USHORT->unsigned short
221 public ushort DesignatorMax;
223 /// USHORT->unsigned short
224 public ushort DataIndexMin;
226 /// USHORT->unsigned short
227 public ushort DataIndexMax;
231 /// Type created in place of an anonymous struct
233 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
234 public struct HIDP_BUTTON_CAPS_NOT_RANGE
237 /// USAGE->USHORT->unsigned short
240 /// USAGE->USHORT->unsigned short
241 public ushort Reserved1;
243 /// USHORT->unsigned short
244 public ushort StringIndex;
246 /// USHORT->unsigned short
247 public ushort Reserved2;
249 /// USHORT->unsigned short
250 public ushort DesignatorIndex;
252 /// USHORT->unsigned short
253 public ushort Reserved3;
255 /// USHORT->unsigned short
256 public ushort DataIndex;
258 /// USHORT->unsigned short
259 public ushort Reserved4;
265 [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
266 public struct HIDP_BUTTON_CAPS
268 /// USAGE->USHORT->unsigned short
270 public ushort UsagePage;
272 /// UCHAR->unsigned char
274 public byte ReportID;
276 /// BOOLEAN->BYTE->unsigned char
278 [MarshalAsAttribute(UnmanagedType.U1)]
281 /// USHORT->unsigned short
283 public ushort BitField;
285 /// USHORT->unsigned short
287 public ushort LinkCollection;
289 /// USAGE->USHORT->unsigned short
291 public ushort LinkUsage;
293 /// USAGE->USHORT->unsigned short
295 public ushort LinkUsagePage;
297 /// BOOLEAN->BYTE->unsigned char
299 [MarshalAsAttribute(UnmanagedType.U1)]
302 /// BOOLEAN->BYTE->unsigned char
304 [MarshalAsAttribute(UnmanagedType.U1)]
305 public bool IsStringRange;
307 /// BOOLEAN->BYTE->unsigned char
309 [MarshalAsAttribute(UnmanagedType.U1)]
310 public bool IsDesignatorRange;
312 /// BOOLEAN->BYTE->unsigned char
314 [MarshalAsAttribute(UnmanagedType.U1)]
315 public bool IsAbsolute;
319 [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.U4)]
320 public uint[] Reserved;
322 /// Union Range/NotRange
324 public HIDP_BUTTON_CAPS_RANGE Range;
327 public HIDP_BUTTON_CAPS_NOT_RANGE NotRange;
331 /// Type created in place of an anonymous struct
333 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
334 public struct HIDP_VALUE_CAPS_RANGE
337 /// USAGE->USHORT->unsigned short
338 public ushort UsageMin;
340 /// USAGE->USHORT->unsigned short
341 public ushort UsageMax;
343 /// USHORT->unsigned short
344 public ushort StringMin;
346 /// USHORT->unsigned short
347 public ushort StringMax;
349 /// USHORT->unsigned short
350 public ushort DesignatorMin;
352 /// USHORT->unsigned short
353 public ushort DesignatorMax;
355 /// USHORT->unsigned short
356 public ushort DataIndexMin;
358 /// USHORT->unsigned short
359 public ushort DataIndexMax;
363 /// Type created in place of an anonymous struct
365 [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
366 public struct HIDP_VALUE_CAPS_NOT_RANGE
369 /// USAGE->USHORT->unsigned short
372 /// USAGE->USHORT->unsigned short
373 public ushort Reserved1;
375 /// USHORT->unsigned short
376 public ushort StringIndex;
378 /// USHORT->unsigned short
379 public ushort Reserved2;
381 /// USHORT->unsigned short
382 public ushort DesignatorIndex;
384 /// USHORT->unsigned short
385 public ushort Reserved3;
387 /// USHORT->unsigned short
388 public ushort DataIndex;
390 /// USHORT->unsigned short
391 public ushort Reserved4;
398 [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
399 public struct HIDP_VALUE_CAPS
402 /// USAGE->USHORT->unsigned short
404 public ushort UsagePage;
406 /// UCHAR->unsigned char
408 public byte ReportID;
410 /// BOOLEAN->BYTE->unsigned char
412 [MarshalAsAttribute(UnmanagedType.U1)]
415 /// USHORT->unsigned short
417 public ushort BitField;
419 /// USHORT->unsigned short
421 public ushort LinkCollection;
423 /// USAGE->USHORT->unsigned short
425 public ushort LinkUsage;
427 /// USAGE->USHORT->unsigned short
429 public ushort LinkUsagePage;
431 /// BOOLEAN->BYTE->unsigned char
433 [MarshalAsAttribute(UnmanagedType.U1)]
436 /// BOOLEAN->BYTE->unsigned char
438 [MarshalAsAttribute(UnmanagedType.U1)]
439 public bool IsStringRange;
441 /// BOOLEAN->BYTE->unsigned char
443 [MarshalAsAttribute(UnmanagedType.U1)]
444 public bool IsDesignatorRange;
446 /// BOOLEAN->BYTE->unsigned char
448 [MarshalAsAttribute(UnmanagedType.U1)]
449 public bool IsAbsolute;
451 /// BOOLEAN->BYTE->unsigned char
453 [MarshalAsAttribute(UnmanagedType.U1)]
456 /// UCHAR->unsigned char
458 public byte Reserved;
460 /// USHORT->unsigned short
462 public ushort BitSize;
464 /// USHORT->unsigned short
466 public ushort ReportCount;
469 /// We had to use 5 ushorts instead of an array to avoid alignment exception issues.
471 public ushort Reserved21;
473 public ushort Reserved22;
475 public ushort Reserved23;
477 public ushort Reserved24;
479 public ushort Reserved25;
481 /// ULONG->unsigned int
483 public uint UnitsExp;
485 /// ULONG->unsigned int
491 public int LogicalMin;
495 public int LogicalMax;
499 public int PhysicalMin;
503 public int PhysicalMax;
505 /// Union Range/NotRange
507 public HIDP_VALUE_CAPS_RANGE Range;
510 public HIDP_VALUE_CAPS_NOT_RANGE NotRange;