4

I'm the author of an open source tool (devreorder) that allows users to specify a stable order for their DirectInput devices. In order for it to work, I need to be able to consistently distinguish between all of the input device connected to the system while enumerating devices using DirectInput 8.

While the DIDEVICEINSTANCE structure passed to a DIEnumDevicesCallback function does contain information that helps identify a device, it does not uniquely identify a device. Even the guidInstance field, which is supposed to always uniquely identify a specific device, is in practice not actually reliable, and it will in some cases change or use the same UUID between two different devices.

Windows does have unique identifiers for devices, though, called its device instance ID. This is also known as the full instance path. I want to use this identifier for DirectInput 8 devices.

So when enumerating devices using IDirectInput8::EnumDevices and being provided a DIDEVICEINSTANCE, is there any way to get the corresponding device instance ID for a particular device?

Bri Bri
  • 2,169
  • 3
  • 19
  • 44
  • Are you looking for `IDirectInputDevice8::GetProperty(DIPROP_GUIDANDPATH)` (note: not supported by all devices)? Sample code here: https://pastebin.com/raw/1V37HX0v – Simon Mourier Jun 07 '23 at 11:02
  • @SimonMourier That may do what I want, though that property appears to be different than the device instance ID / path. Can you say more about how a device's interface path and instance path relate to each other? I'm honestly not sure which can or should be used to uniquely identify a specific device. – Bri Bri Jun 08 '23 at 16:49
  • After doing a bit of cursory research, I think that the device interface path is not what I want to use, and instead I need its instance path. So I think what you wrote gets me halfway there. The remaining half would be figuring out how to get an instance path from an interface path. – Bri Bri Jun 08 '23 at 16:58
  • 1
    Device manager has classes. Each class has device(s) (instances). Each device has interface(s). You have a device interface path (=id), you can get to it's parent device (instance). This tool (using WinRT + C#) https://github.com/smourier/DeviceExplorer can help see the relations https://i.imgur.com/aBf1RLl.png coupled with the results from sample code I gave above – Simon Mourier Jun 08 '23 at 17:09
  • @BriBri - do you have access to Google Bard or GPT? I asked it to write some C++ to get a device interface path from an instance path. No idea if it's correct but it did spit out some code. Maybe worth a shot maybe if you get stuck. Both Bard and GPT use this method: SetupDiEnumDeviceInterfaces – Suraj Jun 08 '23 at 17:14
  • I believe I've figured out how to do it using `CM_Get_Device_Interface_PropertyW`, which these days seems to be preferable to `SetupDiEnumDeviceInterfaces`. – Bri Bri Jun 08 '23 at 17:23
  • With modern Windows ways (WinRT/C++), that would be a code similar to this https://pastebin.com/raw/SUKysr83 (maybe too modern for IDirectInput8 users :-) – Simon Mourier Jun 08 '23 at 17:39

0 Answers0