Getting the device path from the device id

Hi,

in my software I need to inspect the device tree of a newly found device interface to find another device node which I open with a CreateFile.
In order to navigate the device tree I use the CM_* api. The problem is that once I found the node I’m interested into, I need to get somewhere a device path which I can use in the CreateFile.

The only way I found is to get the class GUID of the node that I found, reenumerate via SetupDi… all the interfaces, for each one get the device id and try to find a match. I find it very brute force and I want to believe that there’s a direct way to do this.

Does anybody know a clean solution to this?
Thank you in advance,
ML

To the best of MY knowledge, that IS the clean solution I’m sorry to say.

Peter
OSR
@OSRDrivers

Thank you Peter for your response. It is weirdly comforting.

One more thing: in other to shorten the HDEVINFO list doing the “reverse lookup” I tried to use SetupDiGetClassDevs passing as second argument the device instance id string (I find the vocabulary here a little messy, I mean the one that kind of looks like a device path but it isn’t) and passing DIGCF_PRESENT | DIGCF_DEVICEINTERFACE as flags. I would have expected this to give back basically only the instance I’m interested into. Instead, it fails with “wrong parameters” error, why?

The only thing that seems to work right now is to either get the class GUID of the devnode I’m looking for (getting the value from the registry property classguid) but this doesn’t seem to always work, or to just list ALL the present devices and do basically a string search which works but seems inefficient.

Thanks,
ML

xxxxx@gmail.com wrote:

in my software I need to inspect the device tree of a newly found device interface to find another device node which I open with a CreateFile.
In order to navigate the device tree I use the CM_* api. The problem is that once I found the node I’m interested into, I need to get somewhere a device path which I can use in the CreateFile.

The only way I found is to get the class GUID of the node that I found, reenumerate via SetupDi… all the interfaces, for each one get the device id and try to find a match. I find it very brute force and I want to believe that there’s a direct way to do this.

Does anybody know a clean solution to this?

Are you using CM_Get_Device_Interface_List? The list of strings it
returns ARE the symbolic link file names.

I was involved in a project that initially specified Windows 10 Mobile,
where the SetupDi APIs are not available, but the CM_ APIs are. It
turns out that the CM APIs are, in many cases, much more straightforward.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.