根据 MSDN 文档, SetupDiGetClassDevs 可以传递 设备实例 ID 以获取 特定设备的设备信息集:
要仅返回特定设备,请设置
DIFCF_DEVICEINTERFACE 标志并使用
枚举器参数提供
设备的设备实例ID。
我通过解析 < 中的符号名称来获取设备实例 ID代码>WM_DEVICECHANGE消息DBT_DEVICEARRIVAL
事件,我通过将结果 ID 与从 SetupDiGetDeviceInstanceId。 即使传递操作系统提供的设备实例 ID 也不起作用(即,SetupDiGetClassDevs 调用失败,并显示 ERROR_INVALID_PARAMETER
)。
我当前的解决方法是获取 SP_DEVINFO_DATA
结构对于新到达的设备,枚举同一类中的所有设备并将SetupDiGetDeviceInstanceId 的结果与符号名称进行比较。 但是,我不明白为什么根据文档这应该是必要的...
有人让 SetupDiGetClassDevs 以这种方式工作吗? 是否有更好的方法使用 DBT_DEVICEARRIVAL 事件中的数据获取设备的更多信息?
According to MSDN documentation, SetupDiGetClassDevs can be passed a device instance ID to obtain a device information set for a specific device:
To return only a specific device, set
the DIFCF_DEVICEINTERFACE flag and use
the Enumerator parameter to supply the
device instance ID of the device.
I get the device instance ID by parsing the symbolic name from the WM_DEVICECHANGE
message DBT_DEVICEARRIVAL
event, and I have verified the resulting ID by comparing it to that returned from SetupDiGetDeviceInstanceId. Even passing the OS supplied device instance ID does not work (i.e. the SetupDiGetClassDevs call fails with ERROR_INVALID_PARAMETER
).
My current workaround to fetch a SP_DEVINFO_DATA
structure for the newly arrived device is to enumerate all devices in the same class and compare the result of SetupDiGetDeviceInstanceId to the symbolic name. However, I don't see why this should be necessary according to the documentation...
Has anyone gotten SetupDiGetClassDevs to work in this way? Is there a better method for getting further information for a device using data in the DBT_DEVICEARRIVAL event?
发布评论
评论(2)
看来您必须指定
DIGCF_ALLCLASSES
标志来查找与给定设备实例 id 匹配的所有类,或者指定 ClassGuid 并使用DIGCF_DEFAULT
标志。这对我有用:
输出:
It seems you have to either specify the
DIGCF_ALLCLASSES
flag to find all classes that match the given device instance id, or else specify the ClassGuid and use theDIGCF_DEFAULT
flag.This worked for me:
With output:
您似乎误解了
DBT_DEVICEARRIVAL
。有几种不同类型的
DBT_DEVICEARRIVAL
消息——针对卷、针对句柄、针对设备接口。 我猜您正在谈论 DBT_DEVTYP_DEVICEINTERFACE 品种。 在这种情况下,DEV_BROADCAST_DEVICEINTERFACE
结构的dbcc_name
字段将包含“设备接口路径”。“设备接口路径”与“设备实例 ID”不同。
如果您想了解有关此设备的更多信息,您应该通过此设备接口 GUID 枚举所有设备接口(通过带有 DIGCF_DEVICEINTERFACE 的 SetupDiGetClassDevs),并将 dbcc_name 与
SetupDiEnumDeviceInterfaces< 检索到的字符串进行比较/代码>。
It seems that you're misunderstanding
DBT_DEVICEARRIVAL
.There are a few different types of
DBT_DEVICEARRIVAL
messages-- for a volume, for a handle, for a device interface. I'm guessing you're talking about the DBT_DEVTYP_DEVICEINTERFACE variety. In this case, thedbcc_name
field of theDEV_BROADCAST_DEVICEINTERFACE
structure will contain the "device interface path".The "device interface path" is NOT the same as a "device instance ID".
If you want to know more information about this device, you should enumerate all device interfaces by this device interface GUID (through SetupDiGetClassDevs with DIGCF_DEVICEINTERFACE), and compare the dbcc_name to the strings retrieved by
SetupDiEnumDeviceInterfaces
.