Hello Everyone!
I have recently been trouble-shooting a service that calls
RegisterDeviceNotification to get device change notifications from CDROM
(GUID_DEVCLASS_CDROM) and HID (GUID_DEVCLASS_HIDCLASS) devices. The problem
is, even if the service sent RegisterDeviceNotification (and the function
succeeded), it doesn’t receive any SERVICE_CONTROL_DEVICEEVENT message even
when plugging my CDROM and HID devices (please see the device notification
registration code below).
HDEVNOTIFY DeviceNotificationHandleCD_ROM = NULL;
HDEVNOTIFY DeviceNotificationHandleHID = NULL;
////////////////////////////////////////////////////////////////////
//A. Request Notification from CDROM devices
////////////////////////////////////////////////////////////////////
DEV_BROADCAST_DEVICEINTERFACE DevNtfInterfaceCD_ROM;
memset(&DevNtfInterfaceCD_ROM, 0, sizeof(DevNtfInterfaceCD_ROM));
DevNtfInterfaceCD_ROM.dbcc_size =
sizeof(DEV_BROADCAST_DEVICEINTERFACE);
DevNtfInterfaceCD_ROM.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
DevNtfInterfaceCD_ROM.dbcc_classguid = GUID_DEVCLASS_CDROM;
DeviceNotificationHandleCD_ROM = RegisterDeviceNotification(
MyServiceStatusHandle,
&DevNtfInterfaceCD_ROM,
DEVICE_NOTIFY_SERVICE_HANDLE);
if(DeviceNotificationHandleCD_ROM == NULL){
g_pTempClass->WriteLogWithTime(“CD-ROM Notification request
failed\r\n”);
}
////////////////////////////////////////////////////////////////////
//B. Request notification from HID devices
////////////////////////////////////////////////////////////////////
/*same as above, except that I used GUID_DEVCLASS_HIDCLASS instead of
GUID_DEVCLASS_CDROM*/
However, when I registered with DEVICE_NOTIFY_ALL_INTERFACE_CLASSES, I could
now get SERVICE_CONTROL_DEVICEEVENT notifications from my CDROM and HID
Devices(see code below):
////////////////////////////////////////////////////////////////////
Request Notification from all devices (please forgive me for the ***CDROM***
identifiers here, I just based this from my code above to avoid errors)
////////////////////////////////////////////////////////////////////
DEV_BROADCAST_DEVICEINTERFACE DevNtfInterfaceCD_ROM;
memset(&DevNtfInterfaceCD_ROM, 0, sizeof(DevNtfInterfaceCD_ROM));
DevNtfInterfaceCD_ROM.dbcc_size =
sizeof(DEV_BROADCAST_DEVICEINTERFACE);
DevNtfInterfaceCD_ROM.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
DevNtfInterfaceCD_ROM.dbcc_classguid = GUID_DEVCLASS_CDROM;
//this param will be ignored
DeviceNotificationHandleCD_ROM = RegisterDeviceNotification(
MyServiceStatusHandle,
&DevNtfInterfaceCD_ROM,
DEVICE_NOTIFY_SERVICE_HANDLE |
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
This should have been ok, but the problem is, since
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES is not supported for Win2K
(which is one of our supported OS’s), I can’t use the said flag. What could
have been the problem of my code above(i.e. the code without the
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES)?
Thanks a lot:D