Device Notifications

The system broadcasts a set of default device change events to all applications and services. You do not need to register to receive these default events. See the Remarks section in RegisterDeviceNotification for details. To specify other events your application or service should receive, use the RegisterDeviceNotification function.

When an application or service calls RegisterDeviceNotification, it also specifies the window that will receive the notification events. Services can specify a service status handle instead of a window handle. If a service specifies its service status handle, its service control handler will receive the notification events. For more information, see HandlerEx.

Be sure to handle Plug and Play device events as quickly as possible. Otherwise, the system may become unresponsive. If your event handler is to perform an operation that may block execution (such as I/O), it is best to start another thread to perform the operation asynchronously.

Device notification handles returned by RegisterDeviceNotification must be closed by calling the UnregisterDeviceNotification function when they are no longer needed.

Registering for device notification