RegisterDeviceNotification fails with ERROR_SERVICE_SPECIFIC_ERROR (1066)


I’m trying to activate custom device notification between a kernel mode driver and a user application. As stated on the subject line, my call to RegisterDeviceNotification fails with code 1066, ERROR_SERVICE_SPECIFIC_ERROR. Here’s the code.

DEV_BROADCAST_HANDLE notifyFilter = { 0 };
notifyFilter.dbch_size = sizeof notifyFilter;
notifyFilter.dbch_handle = devHdl; // from CreateFile call with driver name
notifyFilter.dbch_devicetype = DBT_DEVTYP_HANDLE;
itsDevNotifyHdl = RegisterDeviceNotification(m_hWnd, &notifyFilter,
DEVICE_NOTIFY_WINDOW_HANDLE); // returns 0, GetLastError() = 1066

Not much explanation on this error in the MSDN (or WDK) so I searched the web. Many posts related to this very same problem, but offered answers fall into two categories: 1. No answer; 2. use DEV_BROADCAST_DEVICEINTERFACE (DBT_DEVTYPE_DEVICEINTERFACE).

Unfortunately, I cannot use DEV_BROADCAST_DEVICEINTERFACE because I need the DBT_CUSTOMEVENT-only flelds in DEV_BROADCAST_HANDLE.

Ironically, I’ve gotten this to work before in an earlier version of this driver (for a legacy ISA board) based on the old Driver::Works framework. The driver I’m developing now is a straight WDM driver (not KMDF) for a PCI card. The basic driver came with the board kit. It did not have a IRP dispatch routine for WMI, but I added one because ERROR_SERVICE_SPECIFIC_ERROR seems to be related mainly to the WMI classes. That hasn’t made a difference.

Any clues out there as to why RegisterDeviceNotification would fail with ERROR_SERVICE_SPECIFIC_ERROR?