Using PnP Target Device Change Notification

A driver registers for EventCategoryTargetDeviceChange notification on a device so the driver can be notified when the device is about to be removed. For example, if a driver opens a handle to a device, the driver should register for EventCategoryTargetDeviceChange notification on the device so the driver can close its handle when the PnP manager needs to remove the device.

Drivers can also use EventCategoryTargetDeviceChange notification for custom notification. (See Using PnP Custom Notification.)

Important

Registering for PnP target device change notifications is not intended to notify listeners about target device power state changes. If a driver needs to know about a target device power change, the driver should instead define a power relation between devices.

To define a power relation, the driver calls IoInvalidateDeviceRelations with the Type parameter set to PowerRelations, then responds to the PnP manager's IRP_MN_QUERY_DEVICE_RELATIONS query for PowerRelations with the correct information.

The following subsections discuss how to register for target device change notification and how to handle target device change events in a PnP notification callback routine:

Registering for Target Device Change Notification

Handling a GUID_TARGET_DEVICE_QUERY_REMOVE Event

Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE Event

Handling a GUID_TARGET_DEVICE_REMOVE_CANCELLED Event