Registers the device or type of device for which a window will receive notifications.
Syntax
HDEVNOTIFY WINAPI RegisterDeviceNotification(
__in HANDLE hRecipient,
__in LPVOID NotificationFilter,
__in DWORD Flags
);
Parameters
- hRecipient [in]
-
A handle to the window or service 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]
-
A 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, which can be DBT_DEVTYP_DEVICEINTERFACE or DBT_DEVTYP_HANDLE. For more information, see Remarks.
- Flags [in]
-
This parameter can be one of the following values.
| Value | Meaning |
- DEVICE_NOTIFY_WINDOW_HANDLE
- 0x00000000
| The hRecipient parameter is a window handle.
|
- DEVICE_NOTIFY_SERVICE_HANDLE
- 0x00000001
| The hRecipient parameter is a service status handle.
|
In addition, you can specify the following value.
| Value | Meaning |
- DEVICE_NOTIFY_ALL_INTERFACE_CLASSES
- 0x00000004
| Notifies the recipient of device interface events for all device interface classes. (The dbcc_classguid member is ignored.)
This value can be used only if the dbch_devicetype member is DBT_DEVTYP_DEVICEINTERFACE.
Windows 2000: This value is not supported.
|
Return Value
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, SERVICE_CONTROL_DEVICEEVENT notifications are sent to the service control handler. For more information about the service control handler, 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.
The
DBT_DEVICEARRIVAL and
DBT_DEVICEREMOVECOMPLETE events are automatically broadcast to all top-level windows for port devices. Therefore, it is not necessary to call
RegisterDeviceNotification for ports, and the function fails if the dbch_devicetype member is DBT_DEVTYP_PORT. Volume notifications are also broadcast to top-level windows, so the function fails if dbch_devicetype is DBT_DEVTYP_VOLUME. OEM-defined devices are not used directly by the system, so the function fails if dbch_devicetype is DBT_DEVTYP_OEM.
Examples
For an example, see
Registering for Device Notification.
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | Winuser.h (include Windows.h) |
| Library | User32.lib |
| DLL | User32.dll |
| Unicode and ANSI names | RegisterDeviceNotificationW (Unicode) and RegisterDeviceNotificationA (ANSI) |
See Also
- BroadcastSystemMessage
- DEV_BROADCAST_HDR
- Device Management Functions
- Device Notifications
- HandlerEx
- UnregisterDeviceNotification
- WM_DEVICECHANGE
Send comments about this topic to Microsoft
Build date: 5/28/2009