2

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

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.

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

stema
  • 90,351
  • 20
  • 107
  • 135
Vinayaka Karjigi
  • 1,070
  • 5
  • 13
  • 37

2 Answers2

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.

You getDEV_BROADCAST_HEADER* as the LPARAM of WM_DEVICECHANGE.

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Good question, it's not documented as being empty. I presume it could be empty when it's a new device (i.e. never been connected to the PC before), and it's still being installed. But in that case I would expect a new broadcast message when the device is completely installed, that time with `dbcc_name` set. (Note: speculation, I never saw this happen) – MSalters Feb 08 '10 at 09:02
1

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

Alec
  • 11
  • 1