tags:

views:

379

answers:

2

Dear All,

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

But i wanted to know how to get device name of the inserted device.

i found one structure DEV_BROADCAST_DEVICEINTERFACE which is having dbcc_name as member. but i dont know which pointer to type cast to this structure to acess dbcc_name

please help me in this regard Vinayaka Karjigi

A: 

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 get DEV_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
What if dbcc_name is empty?
snicker
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
A: 

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

Alec