7 using System.Runtime.InteropServices;
8 using Microsoft.Win32.SafeHandles;
15 internal const int DIGCF_DEFAULT = 0x00000001;
16 internal const int DIGCF_PRESENT = 0x00000002;
17 internal const int DIGCF_ALLCLASSES = 0x00000004;
18 internal const int DIGCF_PROFILE = 0x00000008;
19 internal const int DIGCF_DEVICEINTERFACE = 0x00000010;
22 internal enum EFileAttributes : uint
24 Readonly = 0x00000001,
27 Directory = 0x00000010,
31 Temporary = 0x00000100,
32 SparseFile = 0x00000200,
33 ReparsePoint = 0x00000400,
34 Compressed = 0x00000800,
36 NotContentIndexed = 0x00002000,
37 Encrypted = 0x00004000,
38 Write_Through = 0x80000000,
39 Overlapped = 0x40000000,
40 NoBuffering = 0x20000000,
41 RandomAccess = 0x10000000,
42 SequentialScan = 0x08000000,
43 DeleteOnClose = 0x04000000,
44 BackupSemantics = 0x02000000,
45 PosixSemantics = 0x01000000,
46 OpenReparsePoint = 0x00200000,
47 OpenNoRecall = 0x00100000,
48 FirstPipeInstance = 0x00080000
51 [StructLayout(LayoutKind.Sequential)]
52 internal struct SP_DEVINFO_DATA
55 public Guid ClassGuid;
57 public IntPtr Reserved;
60 [StructLayout(LayoutKind.Sequential)]
61 internal struct SP_DEVICE_INTERFACE_DATA
64 public Guid InterfaceClassGuid;
66 public IntPtr RESERVED;
69 [StructLayout(LayoutKind.Sequential, Pack = 1)]
70 internal struct SP_DEVICE_INTERFACE_DETAIL_DATA
73 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
74 public string DevicePath;
77 [StructLayout(LayoutKind.Sequential)]
86 [DllImport(
@"hid.dll", CharSet = CharSet.Auto, SetLastError =
true)]
87 internal static extern void HidD_GetHidGuid(out Guid gHid);
89 [DllImport(
"hid.dll")]
90 internal static extern Boolean HidD_GetAttributes(IntPtr HidDeviceObject, ref
HIDD_ATTRIBUTES Attributes);
92 [DllImport(
"hid.dll")]
93 internal extern static bool HidD_SetOutputReport(
94 IntPtr HidDeviceObject,
95 byte[] lpReportBuffer,
96 uint ReportBufferLength);
98 [DllImport(
"hid.dll")]
99 internal extern static bool HidD_GetInputReport(
100 IntPtr HidDeviceObject,
101 byte[] lpREportBuffer,
102 uint ReportBufferLength);
104 [DllImport(
"hid.dll")]
105 internal extern static bool HidD_GetProductString(
106 IntPtr HidDeviceObject,
110 [DllImport(
@"setupapi.dll", CharSet = CharSet.Auto, SetLastError =
true)]
111 internal static extern IntPtr SetupDiGetClassDevs(
113 [MarshalAs(UnmanagedType.LPTStr)]
string Enumerator,
118 [DllImport(
@"setupapi.dll", CharSet = CharSet.Auto, SetLastError =
true)]
119 internal static extern Boolean SetupDiEnumDeviceInterfaces(
122 ref Guid interfaceClassGuid,
124 ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
127 [DllImport(
@"setupapi.dll", SetLastError =
true)]
128 internal static extern Boolean SetupDiGetDeviceInterfaceDetail(
130 ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
131 IntPtr deviceInterfaceDetailData,
132 UInt32 deviceInterfaceDetailDataSize,
133 out UInt32 requiredSize,
134 IntPtr deviceInfoData
137 [DllImport(
@"setupapi.dll", SetLastError =
true)]
138 internal static extern Boolean SetupDiGetDeviceInterfaceDetail(
140 ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
141 ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData,
142 UInt32 deviceInterfaceDetailDataSize,
143 out UInt32 requiredSize,
144 IntPtr deviceInfoData
147 [DllImport(
@"setupapi.dll", CharSet = CharSet.Auto, SetLastError =
true)]
148 internal static extern UInt16 SetupDiDestroyDeviceInfoList(IntPtr hDevInfo);
150 [DllImport(
"Kernel32.dll", SetLastError =
true, CharSet = CharSet.Auto)]
151 internal static extern IntPtr CreateFile(
153 [MarshalAs(UnmanagedType.U4)] UInt32 fileAccess,
154 [MarshalAs(UnmanagedType.U4)] UInt32 fileShare,
155 IntPtr securityAttributes,
156 [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
157 [MarshalAs(UnmanagedType.U4)] EFileAttributes flags,
160 public const uint GENERIC_READ = 0x80000000;
161 public const uint GENERIC_WRITE = 0x40000000;
162 public const uint GENERIC_READ_WRITE = GENERIC_READ | GENERIC_WRITE;
164 public const uint SHARE_NONE = 0;
165 public const uint SHARE_READ = 1;
166 public const uint SHARE_WRITE = 2;
167 public const uint SHARE_READ_WRITE = SHARE_READ | SHARE_WRITE;
168 public const uint SHARE_DELETE = 4;
170 [DllImport(
"Kernel32.dll", SetLastError =
true, CharSet = CharSet.Auto)]
171 internal static extern int WriteFile(
175 out UInt32 bytesWritten,
176 ref
System.Threading.NativeOverlapped lpOverlapped);
178 [DllImport(
"Kernel32.dll", SetLastError =
true, CharSet = CharSet.Auto)]
179 internal static extern int ReadFile(
183 out UInt32 bytesRead,
184 ref
System.Threading.NativeOverlapped lpOverlapped);
186 [DllImport(
"kernel32.dll", SetLastError =
true)]
187 [
return: MarshalAs(UnmanagedType.Bool)]
188 public static extern bool CloseHandle(IntPtr hObject);
190 [StructLayout(LayoutKind.Sequential)]
191 internal struct HIDP_PREPARSED_DATA
194 public Guid InterfaceClassGuid;
196 public IntPtr RESERVED;
199 [StructLayout(LayoutKind.Sequential)]
200 internal struct HIDP_CAPS
203 public ushort UsagePage;
204 public ushort InputReportByteLength;
205 public ushort OutputReportByteLength;
206 public ushort FeatureReportByteLength;
207 public ushort Reserved0;
208 public ushort Reserved1;
209 public ushort Reserved2;
210 public ushort Reserved3;
211 public ushort Reserved4;
212 public ushort Reserved5;
213 public ushort Reserved6;
214 public ushort Reserved7;
215 public ushort Reserved8;
216 public ushort Reserved9;
217 public ushort Reserved10;
218 public ushort Reserved11;
219 public ushort Reserved12;
220 public ushort Reserved13;
221 public ushort Reserved14;
222 public ushort Reserved15;
223 public ushort Reserved16;
224 public ushort NumberLinkCollectionNodes;
225 public ushort NumberInputButtonCaps;
226 public ushort NumberInputValueCaps;
227 public ushort NumberInputDataIndices;
228 public ushort NumberOutputButtonCaps;
229 public ushort NumberOutputValueCaps;
230 public ushort NumberOutputDataIndices;
231 public ushort NumberFeatureButtonCaps;
232 public ushort NumberFeatureValueCaps;
233 public ushort NumberFeatureDataIndices;
236 [DllImport(
"Hid.dll", SetLastError =
true, CharSet = CharSet.Auto)]
237 internal static extern bool HidD_GetPreparsedData(
241 [DllImport(
"Hid.dll", SetLastError =
true, CharSet = CharSet.Auto)]
242 internal static extern bool HidD_FreePreparsedData(
245 [DllImport(
"Hid.dll", SetLastError =
true, CharSet = CharSet.Auto)]
246 internal static extern bool HidP_GetCaps(