SERVICE_CONTROL_DEVICEEVENT不通知拔下“禁用的设备”

请你能告诉我我做错了什么吗?

为什么SERVICE_CONTROL_DEVICEEVENT在插拔“ 禁用的设备 ”(我的意思是禁用设备pipe理器中的设备)时不通知?

如果设备启用,一切工作正常。 这是我的源代码:

  • 注册通知:

     m_hServiceStatus = RegisterServiceCtrlHandlerEx(m_szServiceName, HandlerEx, NULL); if (m_hServiceStatus == NULL) { return; } DWORD dwState = SERVICE_START_PENDING; SetServiceStatus(m_hServiceStatus, &dwState); // Register device notification DEV_BROADCAST_DEVICEINTERFACE notificationFilter; ZeroMemory( &notificationFilter, sizeof(notificationFilter) ); notificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); notificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; if(NULL == (m_hDevNotify = RegisterDeviceNotification(m_hServiceStatus, &notificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE|DEVICE_NOTIFY_ALL_INTERFACE_CLASSES))) { return; } 
  • HandlerEx函数:

     DWORD HandlerEx(DWORD dwOpcode, DWORD dwEventType, LPVOID lpEventData, LPVOID /*lpContext*/) throw() { DWORD dwRes = ERROR_CALL_NOT_IMPLEMENTED; switch (dwOpcode) { case SERVICE_CONTROL_STOP: if (m_hDevNotify) { UnregisterDeviceNotification(m_hDevNotify); m_hDevNotify = NULL; } dwRes = NO_ERROR; break; case SERVICE_CONTROL_SHUTDOWN: if (m_hDevNotify) { UnregisterDeviceNotification(m_hDevNotify); m_hDevNotify = NULL; } dwRes = NO_ERROR; break; case SERVICE_CONTROL_DEVICEEVENT: { // ToDo: process event notification dwRes = NO_ERROR; } break; default: break; } return dwRes; } 

提前谢谢你的帮助!