PnP Notification Overview
The PnP manager provides a mechanism for drivers and applications to be notified when certain events occur on a specific device or on the system in general. A driver can register for notification of the following categories of events:
EventCategoryDeviceInterfaceChange
When a driver registers for this category of events on a device interface, the PnP manager notifies the driver of the following events:
GUID_DEVICE_INTERFACE_ARRIVAL
Indicates that a device interface of the specified class has been enabled. For example, a user added a new disk to the machine and the volume manager enabled a new volume (a device interface of the class "volume").GUID_DEVICE_INTERFACE_REMOVAL
Indicates that a device interface of the specified class has been disabled.See IoRegisterDeviceInterface and related routines for more information about device interfaces.
EventCategoryTargetDeviceChange
When a driver registers for this category of events on a device, the PnP manager notifies the driver when the following events occur on the device:
GUID_TARGET_DEVICE_QUERY_REMOVE
Indicates that the PnP manager is about to remove the drivers for the device. Several actions can cause this event, including: a user has requested to remove the specified device from the machine or a user has issued an update-driver request for the device. This notification requests the drivers for the device to either approve or veto the impending remove operation.GUID_TARGET_DEVICE_REMOVE_COMPLETE
Indicates that the specified device has been removed from the machine or that a user is changing the driver(s) for the device.GUID_TARGET_DEVICE_REMOVE_CANCELLED
Indicates that an impending remove operation on the specified device has been canceled.GUID_XXX (custom events)
Indicates that a custom event has occurred on the specified device.A driver writer can define a custom event for a device. When the driver (or another related component) notifies the PnP manager that the custom event has occurred, the PnP manager notifies any components that registered for target device change notifications on the device.
Unlike registering for device interface changes, which can be considered a "passive" interest in the interface, registering for target device changes indicates an "active" interest in a device.
EventCategoryHardwareProfileChange
This category includes the following events:
GUID_HWPROFILE_QUERY_CHANGE
Indicates that a user has requested to change the hardware profile of the machine. The PnP manager uses this notification to ask registered components whether it can change the hardware profile without disrupting system operation. Registered components typically succeed these query requests.GUID_HWPROFILE_CHANGE_COMPLETE
Indicates that the hardware profile of the machine has changed. If a driver maintains profile-specific settings, such a driver should refresh those settings after a hardware profile change.GUID_HWPROFILE_CHANGE_CANCELLED
Indicates that an impending hardware profile change has been canceled.
PnP notification works as follows for kernel-mode components:
A driver registers for notification on a category of events by calling IoRegisterPlugPlayNotification.
A PnP notification callback routine remains registered until the driver explicitly removes the registration.
The PnP manager calls the driver's callback routine when an event in the registered category occurs.
The driver removes the callback registration by calling IoUnregisterPlugPlayNotification.
Drivers must not generate a synchronous event or wait for an asynchronous event to occur during the processing of a close.
For further information about PnP notification, see the following sections:
Guidelines for Writing PnP Notification Callback Routines
Using PnP Device Interface Change Notification
Using PnP Target Device Change Notification