开发者

Alternatives to Windows 7 device ContainterIDs

开发者 https://www.devze.com 2023-04-12 16:56 出处:网络
How would I identify which devnodes belong to a single physical device in earlier version of windows?

How would I identify which devnodes belong to a single physical device in earlier version of windows?

EDIT:

The reason I would like to do this is because implementing an event system that broadcasts removal events when a device is removed would otherwise require said system to produce more events than necessary for something like an xbox controller (which has 3 interfaces and 2 devnodes). I can开发者_Python百科't find anything other than the ContainerID that I could use to establish correspondence between parts of what comprise a single entity.

I am looking for an alternative that would allow me to determine such a correspondence and allow my program to run on older versions of windows as well.

ANOTHER EDIT:

The ContainerID property is unreliable. I have found 2 entries for xbox 360 controllers with the same ContainerID, yet they correspond to different physical controllers.

I've solved this problem with the following, which works with devices that provide a serial number (e.g. xbox 360 controllers) as well as with those that do not (e.g. cheap, fake PS3 wired USB controllers):

Algorithm:

Find a matching HID device ID for a given USB device ID

input: usb_device_id as a string (e.g. "USB\VID_045E&PID_028E\00E102A")
output: The corresponding HID device ID string

HKEY usb_keys <- open_key("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB")
HKEY hid_keys <- open_key("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID")

HKEY device_key <- open_key("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\"+usb_device_id)

string prefix <- device_key.ParentIdPrefix

retry
for each key in usb_keys
    for each subkey in key
        if prefix occurrs in subkey.name
            prefix <- subkey.ParentIdPrefix
            goto retry
        endif
    endfor
endfor

for each key in hid_keys
    for each subkey in key
        if prefix occurrs in subkey.name
            return "HID\"+key.name+"\"+subkey.name
        endif
    endfor
endfor

return null

I've written this in pseudocode for brevity because the C++ version is quite long (although it uses only one loop instead of two and doesn't involve a goto). Note that key.name refers to the key's name and subkey.ParentIdPrefix means to use RegGetValue to obtain that property. The resulting device ID can be passed to CM_Locate_DevNode. Criticism is welcome, as I am not sure if this is actually as robust as I think it is.


You can discover this relationship using the CM_Get_Parent function.

0

精彩评论

暂无评论...
验证码 换一张
取 消