Use the RegisterDeviceNotification () function for ALL USB devices

I currently have a code that sets up notifications about connected USB-HID devices in a Windows service (written in C ++). The code is as follows:

GUID hidGuid; HidD_GetHidGuid(&hidGuid); DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; NotificationFilter.dbcc_classguid = hidGuid; HDEVNOTIFY deviceNotify = RegisterDeviceNotification(StatusHandle, &NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE); 

The notification is then received through the SERVICE_CONTROL_DEVICEEVENT event. (Remember that this is a Service, therefore there is no WM_DEVICECHANGE).

I thought I could just specify the DEV_BROADCAST_DEVICEINTERFACE flag in the RegisterDeviceNotification () call so that it overrides dbcc_classguid and get all the devices, but it turns out that this flag is not supported in Windows 2000, which is a robber for me. In addition, I assume that this will return more than just USB devices.

How do I change this to get all USB devices, not just USB HID? Should it be as simple as giving a different GUID? Is there a GUID for all USB?

+7
c ++ windows notifications usb
source share
2 answers

Used by GUID_DEVINTERFACE_USB_DEVICE (in "usbiodef.h") to view all USB devices.

  DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); NotificationFilter.dbcc_size = sizeof(NotificationFilter); NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; NotificationFilter.dbcc_reserved = 0; NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE; HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hwnd, &NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE); 
+5
source share

Have you tried GUID_DEVCLASS_USB ? (defined in devguid.h, the Windows SDK)

Did you mean the flag DEVICE_NOTIFY_ALL_INTERFACE_CLASSES ?

In addition, I found the following article useful - this is about the device GUIDs and GUIDs of the interface:

http://blogs.msdn.com/doronh/archive/2006/02/15/532679.aspx

+5
source share

All Articles