Platform SDK: Hardware

RegisterDeviceNotification

The RegisterDeviceNotification function specifies the device or type of device for which a window will receive notifications.

HDEVNOTIFY RegisterDeviceNotification(
  HANDLE hRecipient,
  LPVOID NotificationFilter,
  DWORD Flags
);

Parameters

hRecipient
[in] Handle to the window that will receive device events for the devices specified in the NotificationFilter parameter. The same window handle can be used in multiple calls to RegisterDeviceNotification.

Services can specify either a window handle or service status handle.

NotificationFilter
[in] Pointer to a block of data that specifies the type of device for which notifications should be sent. This block always begins with the DEV_BROADCAST_HDR structure. The data following this header is dependent on the value of the dbch_devicetype member.
Flags
[in] Specifies the handle type. This parameter can be one of the following values.
Type Description
DEVICE_NOTIFY_WINDOW_HANDLE The hRecipient parameter is a window handle.
DEVICE_NOTIFY_SERVICE_HANDLE The hRecipient parameter is a service status handle.

Return Values

If the function succeeds, the return value is a device notification handle.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

Applications send event notifications using the BroadcastSystemMessage function. Any application with a top-level window can receive basic notifications by processing the WM_DEVICECHANGE message. Applications can use the RegisterDeviceNotification function to register to receive device notifications.

Services can use the RegisterDeviceNotification function to register to receive device notifications. If a service specifies a window handle in the hRecipient parameter, the notifications are sent to the window procedure. If hRecipient is a service status handle, the notifications are sent to the service control handler. For more information about the service control handler, see HandlerEx.

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

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 98.
  Header: Declared in Winuser.h; include Windows.h.
  Library: Use User32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows 2000.

See Also

Device Management Overview, Device Management Functions, BroadcastSystemMessage, DEV_BROADCAST_HDR, HandlerEx, UnregisterDeviceNotification, WM_DEVICECHANGE