从DEV_BROADCAST_DEVICEINTERFACE win32编程获取dbcc_name

时间:2022-09-06 14:41:03

I have some c code with me which detects the usb cable removal and insertion.

我有一些c代码,可以检测usb电缆的拆卸和插入。

I found one structure DEV_BROADCAST_DEVICEINTERFACE which is having dbcc_name as member. but I don't know which pointer to type cast to this structure to access dbcc_name.

我找到了一个结构DEV_BROADCAST_DEVICEINTERFACE,它有dbcc_name作为成员。但我不知道哪个指向类型转换为此结构的指针来访问dbcc_name。

How can I get the device name of the inserted device.

如何获取插入设备的设备名称。

2 个解决方案

#1


You need to cast a DEV_BROADCAST_HEADER* to a DEV_BROADCAST_DEVICEINTERFACE*. You are allowed to do so if and only if dbch_devicetype==DBT_DEVTYP_DEVICEINTERFACE.

您需要将DEV_BROADCAST_HEADER *转换为DEV_BROADCAST_DEVICEINTERFACE *。当且仅当dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE时,才允许这样做。

You getDEV_BROADCAST_HEADER* as the LPARAM of WM_DEVICECHANGE.

你得到DEV_BROADCAST_HEADER *作为WM_DEVICECHANGE的LPARAM。

To do something useful with dbcc_name, you have to pass it to SetupDiOpenDeviceInterface(). This will give you a SP_DEVICE_INTERFACE_DATA with one SP_DEVINFO_DATA. You can then call functions like SetupDiGetDeviceRegistryProperty to learn more about the device.

要对dbcc_name执行有用的操作,必须将其传递给SetupDiOpenDeviceInterface()。这将为您提供SP_DEVICE_INTERFACE_DATA和一个SP_DEVINFO_DATA。然后,您可以调用SetupDiGetDeviceRegistryProperty等函数来了解有关该设备的更多信息。

#2


Please notice the CodeSet. If it is Unicode. The data is \\0......

请注意CodeSet。如果是Unicode。数据是\\ 0 ......

#1


You need to cast a DEV_BROADCAST_HEADER* to a DEV_BROADCAST_DEVICEINTERFACE*. You are allowed to do so if and only if dbch_devicetype==DBT_DEVTYP_DEVICEINTERFACE.

您需要将DEV_BROADCAST_HEADER *转换为DEV_BROADCAST_DEVICEINTERFACE *。当且仅当dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE时,才允许这样做。

You getDEV_BROADCAST_HEADER* as the LPARAM of WM_DEVICECHANGE.

你得到DEV_BROADCAST_HEADER *作为WM_DEVICECHANGE的LPARAM。

To do something useful with dbcc_name, you have to pass it to SetupDiOpenDeviceInterface(). This will give you a SP_DEVICE_INTERFACE_DATA with one SP_DEVINFO_DATA. You can then call functions like SetupDiGetDeviceRegistryProperty to learn more about the device.

要对dbcc_name执行有用的操作,必须将其传递给SetupDiOpenDeviceInterface()。这将为您提供SP_DEVICE_INTERFACE_DATA和一个SP_DEVINFO_DATA。然后,您可以调用SetupDiGetDeviceRegistryProperty等函数来了解有关该设备的更多信息。

#2


Please notice the CodeSet. If it is Unicode. The data is \\0......

请注意CodeSet。如果是Unicode。数据是\\ 0 ......