Hidd_Get*String functions don't work for builtin touchpad and keyboard

Wallby 46 Reputation points
2024-05-15T11:33:49.5166667+00:00

Hello,

I have an application where I try to get a human readable string for raw input devices.

I first get the devicename by running the following code twice. First with devicename == NULL, then allocate memory for the devicename, and then again to write to devicename.

SetLastError(ERROR_SUCCESS);
// ^
// not sure if GetRawInputDeviceInfoA always sets last error, but..
// .. documentation doesn't mention any return value that indicates an..
// .. error
if(GetRawInputDeviceInfoA(hDevice, RIDI_DEVICENAME, devicename, devicenameLength) == -1) //< can only return -1 if devicename != NULL
{
  //...
  return 0;
}
if(GetLastError() != ERROR_SUCCESS)
{
  //... //< output using GetLastError and FormatMessageA
  return 0;
}

Then I use CreateFileA..

HANDLE a = CreateFileA(devicename, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(a == NULL)
{
  //... //< output using GetLastError and FormateMessageA
}

Then I use these three HidD_Get*String functions..

WCHAR productstring[127];
WCHAR manufacturerstring[127];
WCHAR serialnumberstring[127];
productstring[0] = L'\0';
manufacturerstring[0] = L'\0';
serialnumberstring[0] = L'\0';

if(HidD_GetProductString(a, productstring, sizeof(WCHAR) * 127) == FALSE)
{
  //... //< output using GetLastError and FormatMessageA
}

if(HidD_GetManufacturerString(a, manufacturerstring, sizeof(WCHAR) * 127) == FALSE)
{
  //... //< output using GetLastError and FormatMessageA
}

if(HidD_GetSerialNumberString(a, serialnumberstring, sizeof(WCHAR) * 127) == FALSE)
{
  //... //< output using GetLastError and FormatMessageA
}

CloseHandle(a);
				
wprintf(L"productstring is \"%s\"\n", productstring);
wprintf(L"manufacturerstring is \"%s\"\n", manufacturerstring);
wprintf(L"serialnumberstring is \"%s\"\n", serialnumberstring);

The //... here means continuing the loop this is in to the next raw input device. The initial hDevice is from RAWINPUTDEVICELIST from GetRawInputDeviceList. The loop goes over every element from GetRawInputDeviceList.

I only do this for keyboards (RIM_TYPEKEYBOARD) and mice (RIM_TYPEMOUSE) currently. There are 3 keyboards and 2 mice detected.

I have a Logitech mouse with a USB receiver. For this there are two raw input devices listed, one "keyboard", which in device manager (looked up using the RIDI_DEVICENAME) is "HID Keyboard Device 2", and one mouse, which in device manager is "HID-compliant mouse 2".

This is on a laptop with a built in keyboard and a built in mouse. The other two keyboards are one which in device manager is "HID Keyboard Device 1" and one which in device manager is "Standard PS/2 Keyboard". The mouse (RIM_TYPEMOUSE) for the touchpad in device manager is "HID-compliant mouse 1".

Here is every RIDI_DEVICENAME..

\\?\HID#VID_046D&PID_C539&MI_01&Col01#7&1503b362&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
\\?\HID#VID_046D&PID_C539&MI_00#7&1d39724&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
\\?\HID#VID_06CB&PID_2970&Col01#6&4e814c3&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
HidDeviceObject is 0000000000000238
\\?\HID#VID_046D&PID_C232#2&33191fed&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
\\?\ACPI#10250759#4&2f80d4b8&0#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}

The first two are for the logitech mouse. The third is for the built in touchpad. The last two are for the built in keyboard.

For the first three (the Logitech mouse and the built in touchpad) HidD_GetProductString and HidD_GetManufacturerString work, but HidD_GetSerialNumberString fails with an error "The parameter is incorrect.". Only for the Logitech mouse is there actually anything in the productstring and manufacturerstring, for the built in touchpad they both only contain one space.

For the fourth all three functions fail and the output of GetLastError and FormatMessageA is.. The supplied user buffer is not valid for the requested operation.

For the last all three functions fail as well and the output is.. The parameter is incorrect.

I assumed that these are all USB devices because of the documentation on usage pages "For detailed information about industry standard HID usage, see the Universal Serial Bus (USB) specification HID Usage Tables that is located at the USB Implementers Forum website." from https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/hid-usages.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,824 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,637 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.