Lakeview Research home > USB Central > HID Page > The HID FAQ
The HID FAQ
Frequently asked questions relating to designing hardware and writing program code for USB devices in the Human Interface Device (HID) class
by Jan Axelson
This FAQ contains questions frequently asked on the USB Developer's Forum and other questions I've received by e-mail. The FAQ is a supplement to the information on my HID Page. Suggestions and contributions welcome via
Sending and Receiving Reports under Windows
How can an application request a report using a control transfer?
HidD_GetFeature requests a Feature report using a control transfer with a Get_Report request. Beginning with Windows XP, you can use HidD_GetInputReport to request an Input report with a control transfer and a Get_Report request.
How can an application send a report using a control transfer?
Under Windows 98 Gold (original version), WriteFile sends Output reports using control transfers with Set_Report requests. Under later Windows editions, WriteFile uses control transfers if the HID interface doesn't have an interrupt OUT endpoint. Otherwise, WriteFile uses interrupt transfers for Output reports. Beginning with Windows XP, you can use HidD_SetInputReport to send an Output report with a control transfer and a Set_Report request. Under all Windows editions, HidD_SetFeature sends a Feature report using a control transfer with a Set_Report request.
How can an application request reports using interrupt transfers?
Use ReadFile or ReadFileEx. The first byte in the buffer is the Report ID
How can an application send reports using an interrupt transfers?
Use WriteFile. The Windows edition must be later than Windows 98 Gold (original version), the device's USB version and HID interface must be version 1.1 or later, and the HID interface must have an interrupt OUT endpoint. The first byte in the buffer is the Report ID.
How large is the ReadFile buffer?
Under Windows 98 Gold, 2 reports. Under Windows 98 SE, Windows 2000 and Windows Me, the default is 8 reports. Under Windows XP, the default is 32 reports. Under all but Windows 98 Gold, you can change the defaults with HidD_SetNumInputBuffers. The maximum size under Windows XP and later is 512. The maximum size under Windows 2000 is 200. Use HidD_GetNumInputBuffers to read the buffer size.
Where is the Windows documentation for accessing HIDs?
In the Windows DDK, currently under Interactive Input Devices.
Do I need the Windows DDK to create applications that access HIDs?
C programmers will need the files hid.h and hidsdi.h, which as far as I know are included only in the Windows DDK. My Visual Basic and Visual Basic .NET example applications include VB declarations for many of the API functions used in accessing HIDs, and these applications will compile without the DDK.
Does every HID require an interrupt IN endpoint and an Input report?
The HID spec says that every HID must have an interrupt IN endpoint. Reports are that a HID without an interruput IN endpoint and an Input report will not work on some operating systems.
Why do I receive "Access denied" when attempting to access my HID?
Windows 2000 and Windows XP have exclusive read/write access to HIDs that are configured as a system keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not requesting READ or WRITE access with CreateFile. Communications can then use HidD_SetFeature and HidD_GetFeature (assuming the device supports Feature reports).
How can applications receive Input reports from a system mouse or keyboard?
Windows XP supports the raw input model to enable reading Input reports when communicating with system mice and keyboards. For more information, search microsoft.com for "raw input".
On a system with multiple keyboards, mice, or joysticks how can my application determine which device is sending data?
Use raw input (see previous question).
Debugging
How can I keep my application from losing reports?
If the ReadFile buffer is full, on receiving a new report, the driver drops the oldest report. To prevent this from happening, use HidD_SetNumInputBuffers to increase the buffer size (not available under Windows 98 Gold), use longer reports sent less frequently, have the application read reports more often, or increase the size of the buffer in the call to ReadFile. (ReadFile returns as many reports as are available, up to ReadFile's buffer size.)
Why does ReadFile hang my application when I request to read a report?
ReadFile returns when one of more reports of the expected size are available.
How can I find out if a report is available without hanging my application?
Use overlapped ReadFile with a short timeout or use ReadFileEx to signal when a report is available. In .NET, you can do asynchronous ReadFiles with a delegate and BeginInvoke and EndInvoke methods.
Why do I receive "CRC Error" when attempting to send a report to my device?
This error can be caused by any of a number of firmware errors that results in the host's not seeing a valid response after sending a report.
How do Windows and Mac OS X handle multiple applications accessing the same HID?
Every open handle to the HID has its own report queue. Every report a device sends goes into all of the queues so multiple applications can read the same report.
