2 * ReactOS Hid User Library
3 * Copyright (C) 2004 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * PROJECT: ReactOS Hid User Library
23 * PURPOSE: ReactOS Hid User Library
29 #include <ddk/hidusage.h>
30 #include <ddk/hidclass.h>
31 #include <ddk/hidpi.h>
34 HINSTANCE hDllInstance
;
36 /* device interface GUID for HIDClass devices */
37 const GUID HidClassGuid
= {0x4D1E55B2, 0xF16F, 0x11CF, {0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30}};
40 DllMain(HINSTANCE hinstDLL
,
46 case DLL_PROCESS_ATTACH
:
47 hDllInstance
= hinstDLL
;
50 case DLL_THREAD_ATTACH
:
53 case DLL_THREAD_DETACH
:
56 case DLL_PROCESS_DETACH
:
64 * HidD_FlushQueue EXPORTED
70 HidD_FlushQueue(IN HANDLE HidDeviceObject
)
73 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_FLUSH_QUEUE
,
81 * HidD_FreePreparsedData EXPORTED
87 HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData
)
89 return (LocalFree((HLOCAL
)PreparsedData
) == NULL
);
94 * HidD_GetAttributes EXPORTED
100 HidD_GetAttributes(IN HANDLE HidDeviceObject
,
101 OUT PHIDD_ATTRIBUTES Attributes
)
103 HID_COLLECTION_INFORMATION hci
;
106 if(!DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
,
108 &hci
, sizeof(HID_COLLECTION_INFORMATION
),
114 /* copy the fields */
115 Attributes
->Size
= sizeof(HIDD_ATTRIBUTES
);
116 Attributes
->VendorID
= hci
.VendorID
;
117 Attributes
->ProductID
= hci
.ProductID
;
118 Attributes
->VersionNumber
= hci
.VersionNumber
;
125 * HidP_GetButtonCaps EXPORTED
131 HidP_GetButtonCaps(IN HIDP_REPORT_TYPE ReportType
,
132 OUT PHIDP_BUTTON_CAPS ButtonCaps
,
133 IN OUT PULONG ButtonCapsLength
,
134 IN PHIDP_PREPARSED_DATA PreparsedData
)
136 return HidP_GetSpecificButtonCaps(ReportType
, 0, 0, 0, ButtonCaps
,
137 ButtonCapsLength
, PreparsedData
);
142 * HidD_GetFeature EXPORTED
148 HidD_GetFeature(IN HANDLE HidDeviceObject
,
149 OUT PVOID ReportBuffer
,
150 IN ULONG ReportBufferLength
)
153 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_FEATURE
,
155 ReportBuffer
, ReportBufferLength
,
161 * HidD_GetHidGuid EXPORTED
167 HidD_GetHidGuid(OUT LPGUID HidGuid
)
169 *HidGuid
= HidClassGuid
;
174 * HidD_GetInputReport EXPORTED
180 HidD_GetInputReport(IN HANDLE HidDeviceObject
,
181 IN OUT PVOID ReportBuffer
,
182 IN ULONG ReportBufferLength
)
185 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_INPUT_REPORT
,
187 ReportBuffer
, ReportBufferLength
,
193 * HidD_GetManufacturerString EXPORTED
199 HidD_GetManufacturerString(IN HANDLE HidDeviceObject
,
201 IN ULONG BufferLength
)
204 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_MANUFACTURER_STRING
,
206 Buffer
, BufferLength
,
212 * HidD_GetNumInputBuffers EXPORTED
218 HidD_GetNumInputBuffers(IN HANDLE HidDeviceObject
,
219 OUT PULONG NumberBuffers
)
222 return DeviceIoControl(HidDeviceObject
, IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS
,
224 NumberBuffers
, sizeof(ULONG
),
230 * HidD_GetPhysicalDescriptor EXPORTED
236 HidD_GetPhysicalDescriptor(IN HANDLE HidDeviceObject
,
238 IN ULONG BufferLength
)
241 return DeviceIoControl(HidDeviceObject
, IOCTL_GET_PHYSICAL_DESCRIPTOR
,
243 Buffer
, BufferLength
,
249 * HidD_GetPreparsedData EXPORTED
255 HidD_GetPreparsedData(IN HANDLE HidDeviceObject
,
256 OUT PHIDP_PREPARSED_DATA
*PreparsedData
)
258 HID_COLLECTION_INFORMATION hci
;
262 if(PreparsedData
== NULL
)
267 if(!DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
,
269 &hci
, sizeof(HID_COLLECTION_INFORMATION
),
275 *PreparsedData
= LocalAlloc(LHND
, hci
.DescriptorSize
);
276 if(*PreparsedData
== NULL
)
278 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
282 Ret
= DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_COLLECTION_DESCRIPTOR
,
284 *PreparsedData
, hci
.DescriptorSize
,
289 /* FIXME - Free the buffer in case we failed to get the descriptor? */
290 LocalFree((HLOCAL
)*PreparsedData
);
295 /* should we truncate the memory in case RetLen < hci.DescriptorSize? */
304 * HidD_GetProductString EXPORTED
310 HidD_GetProductString(IN HANDLE HidDeviceObject
,
312 IN ULONG BufferLength
)
315 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_PRODUCT_STRING
,
317 Buffer
, BufferLength
,
323 * HidD_GetSerialNumberString EXPORTED
329 HidD_GetSerialNumberString(IN HANDLE HidDeviceObject
,
331 IN ULONG BufferLength
)
334 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_GET_SERIALNUMBER_STRING
,
336 Buffer
, BufferLength
,
342 * HidP_GetValueCaps EXPORTED
348 HidP_GetValueCaps(IN HIDP_REPORT_TYPE ReportType
,
349 OUT PHIDP_VALUE_CAPS ValueCaps
,
350 IN OUT PULONG ValueCapsLength
,
351 IN PHIDP_PREPARSED_DATA PreparsedData
)
353 return HidP_GetSpecificValueCaps(ReportType
, 0, 0, 0, ValueCaps
,
354 ValueCapsLength
, PreparsedData
);
359 * HidD_Hello EXPORTED
361 * Undocumented easter egg function. It fills the buffer with "Hello\n"
362 * and returns number of bytes filled in (lstrlen(Buffer) + 1 == 7)
364 * Bugs: - doesn't check Buffer for NULL
365 * - always returns 7 even if BufferLength < 7 but doesn't produce a buffer overflow
371 HidD_Hello(OUT PCHAR Buffer
,
372 IN ULONG BufferLength
)
374 const PCHAR HelloString
= "Hello\n";
375 ULONG StrSize
= (lstrlenA(HelloString
) + 1) * sizeof(CHAR
);
379 memcpy(Buffer
, HelloString
, min(StrSize
, BufferLength
));
387 * HidD_SetFeature EXPORTED
393 HidD_SetFeature(IN HANDLE HidDeviceObject
,
394 IN PVOID ReportBuffer
,
395 IN ULONG ReportBufferLength
)
398 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_FEATURE
,
399 ReportBuffer
, ReportBufferLength
,
406 * HidD_SetNumInputBuffers EXPORTED
412 HidD_SetNumInputBuffers(IN HANDLE HidDeviceObject
,
413 IN ULONG NumberBuffers
)
416 return DeviceIoControl(HidDeviceObject
, IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS
,
417 &NumberBuffers
, sizeof(ULONG
),
424 * HidD_SetOutputReport EXPORTED
430 HidD_SetOutputReport(IN HANDLE HidDeviceObject
,
431 IN PVOID ReportBuffer
,
432 IN ULONG ReportBufferLength
)
435 return DeviceIoControl(HidDeviceObject
, IOCTL_HID_SET_OUTPUT_REPORT
,
436 ReportBuffer
, ReportBufferLength
,