Using PnP Custom Notification
A driver can use the target device change notification mechanism to be notified of custom events on a device.
The programmer that defines the custom event must do the following:
Define a new GUID for the custom event.
Generate the GUID with Uuidgen or Guidgen (which are included in the Microsoft Windows SDK). Publish the GUID in an appropriate header file and documentation.
Write code to trigger the custom event.
In kernel mode, a driver calls IoReportTargetDeviceChange with the custom GUID and a pointer to the PDO for the device. Custom events can only be triggered from kernel mode.
A driver writer uses custom notification with a procedure like the following:
The driver (or application) registers for notification of the custom event.
In kernel mode, a driver calls IoRegisterPlugPlayNotification and registers for an EventCategoryTargetDeviceChange on the device.
In user mode, an application registers using RegisterDeviceNotification. See the Windows SDK for further information.
A kernel-mode component triggers the custom event.
The PnP manager calls notification routines registered on the device.
The PnP manager calls the registered user-mode callback routines and then calls the kernel-mode callback routines.
When user-mode notification is complete, the kernel-mode driver notification callback routine(s) respond to the custom event.
See Guidelines for Writing PnP Notification Callback Routines for general guidelines for notification callback routines. In addition to those guidelines, a custom notification callback routine must not open a handle to a device from within the callback routine thread.