I can tell how many USB HID devices I have (7), but every time I try to get the details on any device, the path returned for it is always "\", so I canβt access the device at all. I use code that is very similar in procedure to this code:
HANDLE connectDeviceNumber(DWORD deviceIndex)
{
GUID hidGUID;
HDEVINFO hardwareDeviceInfoSet;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
PSP_INTERFACE_DEVICE_DETAIL_DATA deviceDetail;
ULONG requiredSize;
HANDLE deviceHandle = INVALID_HANDLE_VALUE;
DWORD result;
HidD_GetHidGuid (&hidGUID);
hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID,
NULL,
NULL,
(DIGCF_PRESENT |
DIGCF_DEVICEINTERFACE));
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet,
NULL,
&hidGUID,
deviceIndex,
&deviceInterfaceData);
if (result == FALSE)
{
SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
Log("hidin: -- failed to get specified device number");
return INVALID_HANDLE_VALUE;
}
SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
&deviceInterfaceData,
NULL,
0,
&requiredSize,
0);
deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
&deviceInterfaceData,
deviceDetail,
requiredSize,
&requiredSize,
NULL))
{
SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
free (deviceDetail);
Log("hidin: -- failed to get device info");
return INVALID_HANDLE_VALUE;
}
Log("Opening device with path: %s", deviceDetail->DevicePath);
source
share