1

I have C++ code (works well with VS6 up to VS2017) that enumerates USB devices and retrieves several properties. I recently added SPDRP_DEVTYPE:

SetupDiGetDeviceRegistryProperty(hDevInfo, &DevData, SPDRP_DEVTYPE, 0L, (BYTE*) &dwData, 4, 0);

The call returns with 'false' and GetLastError() then returns 13 ("The data is invalid"). The same happens when trying to query for SPDRP_CHARACTERISTICS.

Most other PropertyKey values I have tried work well (for example, SPDRP_CAPABILITIES, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, SPDRP_FRIENDLYNAME, and so on) but these two keep failing.

Running the EXE as administrator does not change anything. I tested on Windows 7 (32/64) and on Windows 10.

In addition, I tried to open the device with CreateFile (which succeeds) and then use DeviceIoControl(), but every call to DeviceIoControl fails with Error 50 "not supported"

Any idea why these calls are not working?

user3677092
  • 31
  • 1
  • 4
  • Just for info (and for possible close-voters): (1) I can reproduce this error with the information given. (2) It is also mentioned in [this answer](https://stackoverflow.com/a/4947865/10871073), from 10 years ago. (3) I have tried - and failed - to resolve the issue. – Adrian Mole Jan 26 '21 at 11:32
  • @Adrian: thanks - my primary goal is to filter "USB mass storage" devices - SPDRP_DEVICEDESC works, but returns a language string, so I don't like this option. Do you maybe have an idea how to do this ? – user3677092 Jan 26 '21 at 13:08
  • I tried a few things. I have code in a project that uses `SPDRP_FRIENDLYNAME` successfully, but fails with `SPDRP_DEVTYPE`, as yours does. None of the 'obvious' changes that I tried made any difference. Let's see if anyone here can help. – Adrian Mole Jan 26 '21 at 13:11
  • The behavior you observe is [documented](https://learn.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupdigetdeviceregistrypropertyw): *"`SetupDiGetDeviceRegistryProperty` returns the `ERROR_INVALID_DATA` error code if the requested property does not exist for a device or if the property data is not valid."* Your code needs to be prepared to handle this case gracefully. – IInspectable Jan 26 '21 at 13:12
  • https://learn.microsoft.com/en-us/windows-hardware/drivers/install/determining-which-properties-are-set-for-a-device-instance – Hans Passant Jan 26 '21 at 15:53

0 Answers0