views:

1830

answers:

2

I currently have some code that sets up notifications of connected USB HID devices within 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);

A notification is then received via the SERVICE_CONTROL_DEVICEEVENT event. (Remember, this is a Service so no WM_DEVICECHANGE).

I thought I could just specify the DEV_BROADCAST_DEVICEINTERFACE flag in the RegisterDeviceNotification() call so it would override dbcc_classguid and get all devices, but it turns out that that flag is not supported on Windows 2000, which is a dealbreaker for me. Also, I'm guessing that that would return more than just USB devices.

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

+1  A: 

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

Did you mean the DEVICE_NOTIFY_ALL_INTERFACE_CLASSES flag?

Also, I found the following article helpful - it's about device GUIDs vs interface GUIDs:

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

snowcrash09
+1  A: 

Used GUID_DEVINTERFACE_USB_DEVICE (in "usbiodef.h") to watch for 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);