I have two HID compliant devices from logitech ( VendorID 0x046d == 1133 ) : the K120 keyboard ( ProductID 0xC31C == 49948 ) and the B100 mouse ( ProductID 0xc05a == 49242 )
I can successfully talk to the keyboard using the HID class support routines https://msdn.microsoft.com/en-us/library/windows/hardware/ff538865(v=vs.85).aspx
Although the control panel shows the mouse installs properly, and it certainly works as a mouse, every HID class routine returns failure.
This code shows HidD_GetAttributes working on the keyboard but not the mouse
#include <iostream>
#include <windows.h>
#include <setupapi.h>
#include <ddk/hidsdi.h>
using namespace std;
int main()
{
// get info set for all present HIDs
GUID HID_GUID;
HidD_GetHidGuid( & HID_GUID );
HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
&HID_GUID,
NULL,NULL,
DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
SP_DEVICE_INTERFACE_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
int DeviceIndex = 0;
// loop over present HIDs
while ( SetupDiEnumDeviceInterfaces(
DeviceInfoSet,
NULL,
&HID_GUID,
DeviceIndex,
&DeviceInfoData))
{
DeviceIndex++;
//Get the details with null values to get the required size of the buffer
PSP_INTERFACE_DEVICE_DETAIL_DATA deviceDetail;
ULONG requiredSize = 0;
SetupDiGetDeviceInterfaceDetail (DeviceInfoSet,
&DeviceInfoData,
NULL, //interfaceDetail,
0, //interfaceDetailSize,
&requiredSize,
0); //infoData))
//Allocate the buffer
deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
//Fill the buffer with the device details
if (!SetupDiGetDeviceInterfaceDetail (DeviceInfoSet,
&DeviceInfoData,
deviceDetail,
requiredSize,
&requiredSize,
NULL))
{
cout << "SetupDiGetDeviceInterfaceDetail failed";
continue;
}
// open the HID handle
string myPath = deviceDetail->DevicePath;
HANDLE myHandle = CreateFile(myPath.c_str(),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if( ! myHandle )
{
cout << "Create File failed";
continue;
}
// get attributes of HID
int myVendorID;
int myProductID;
_HIDD_ATTRIBUTES attributes;
attributes.Size = sizeof( _HIDD_ATTRIBUTES );
if( HidD_GetAttributes(
myHandle,
&attributes ) )
{
myVendorID = attributes.VendorID;
myProductID = attributes.ProductID;
}
else
{
// failure
myVendorID = -1;
myProductID = -1;
}
// display logitech devices
if( myPath.find("vid_046d") != -1 )
cout << myPath.substr(0,30) << "... VID: " << myVendorID
<< " PID " << myProductID << endl << endl;
}
return 0;
}
Output is:
\\?\hid#vid_046d&pid_c05a#7&be... VID: -1 PID -1 \\?\hid#vid_046d&pid_c31c&mi_0... VID: 1133 PID 49948 \\?\hid#vid_046d&pid_c31c&mi_0... VID: 1133 PID 49948 \\?\hid#vid_046d&pid_c31c&mi_0... VID: 1133 PID 49948 \\?\hid#vid_046d&pid_c31c&mi_0... VID: -1 PID -1
Why can I not access the mouse?