views:

274

answers:

3

I've got some bar code scanner devices that can handle a variety of USB interfaces (COMM Emulation, HID Keyboard, HID POS, etc.) The problem is that, while I can tell if the device is in a HID mode, I need to be able to determine if it's HID Keyboard or HID POS.

Is there a way to determine this using Win32 C++, preferably with the built in windows HID library (hidsdi.h)?

+2  A: 

You can use HidD_GetHidGuid to get the unique GUID for the device. Device interface guids are defined by each device/application software vendor, Microsoft or third party as they see fit. In some cases the guids are published and public knowledge and are standard interfaces, in some cases they are not.

You can also use the USBView utility from Microsoft which will let you browse the USB tree or you can look in the registry and see if you can find the GUID for your device. You may still have to query your device to determine device type if the config data is not present or it does not reveal itself other than a generic device, if your device supports this.

There are two types of GUIDs: Device Class and Device Interface. A device can only be a part of one class. Unfortunately, the Device Class and Device Interface GUIDs are sometimes the same, thus confusing developers. In the WinXP DDK, standards were created to try and make the definition of GUIDs less confusing.

See also this previous SO question: Use RegisterDeviceNotification() for ALL USB devices.

0A0D
That might work, but is there a list of the GUIDs somewhere? The GUID won't mean anything to me otherwise.
Adam Haile
see edit [15 chars]
0A0D
+1  A: 

Here is a list of possible HID Guids: http://msdn.microsoft.com/en-us/library/ms791134.aspx and use HidD_GetHidGuid as Roboto suggested

Victor Hurdugaci
Ok, closer now, but that list includes just one entry for HID, but I need HID POS vs HID Keyboard. POS is bi-directional and keyboard is unidirectional, so they are definitely different. Maybe this can't be determined with HidD_GetHidGuid ?
Adam Haile
What GUIDs do you get in POS mode and Keyboard mode? Is the same?
Victor Hurdugaci
Yes, it's the same, and the one listed here: http://msdn.microsoft.com/en-us/library/bb663084.aspxWhich is just for HID in general
Adam Haile
Remember, you have device class GUID and device interface GUID. They are different
0A0D
they always show up as the base HID GUID
Adam Haile
@Adam: Did you try the USBView utility in my answer?
0A0D
Yes, but it didn't show GUIDs
Adam Haile
If you search the registry under HKEY_LM\SYSTEM\ControlSet001\Control\Class you will find the GUID by searching for the VendorName/ProviderName (or look under CurrentControlSet)
0A0D
A: 

You'll need to use the HidP_ functions to check the hid report capabilities. Find out what capabilities (usages) are presented by the HIDPOS device, and check if those usages are present using HidD_GetPreparsedData(), HidP_GetCaps() and then HidP_GetValueCaps(and/or ..ButtonCaps, etc). A good place to look for examples is Jan Axelson's page. If the usages are present, then you've got the POS device. If not, then it must be the keyboard (assuming you've confirmed the device is attached.)

Bob