CM_Unregister_Notification function
Use UnregisterDeviceNotification instead of CM_Unregister_Notification if your code targets Windows 7 or earlier versions of Windows.
The CM_Unregister_Notification function closes the specified HCMNOTIFICATION handle.
Syntax
CMAPI CONFIGRET WINAPI CM_Unregister_Notification( _In_ HCMNOTIFICATION NotifyContext );
Parameters
- NotifyContext [in]
-
The HCMNOTIFICATION handle returned by the CM_Register_Notification function.
Return value
If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
Remarks
Do not call CM_Unregister_Notification from a notification callback. Doing so may cause a deadlock because CM_Unregister_Notification waits for pending callbacks to finish.
Instead, if you want to unregister from the notification callback, you must do so asynchronously. The following sequence shows one way to do this:
- Allocate a context structure to use with your notifications. Include a pointer to a threadpool work structure (PTP_WORK) and any other information you would like to pass to the notification callback.
- Call CreateThreadpoolWork. Provide a callback function that calls CM_Unregister_Notification. Add the returned work structure to the previously allocated context structure.
- Call CM_Register_Notification and provide the context structure as the pContext parameter.
- Do work, get notifications, etc.
- Call SubmitThreadpoolWork from within the notification callback, providing the pointer to a threadpool work structure (PTP_WORK) stored in your context structure.
- When the threadpool thread runs, the work item calls CM_Unregister_Notification.
- Call CloseThreadpoolWork to release the work object.
If you are finished with the context structure, don't forget to release resources and and free the structure.
Requirements
|
Target platform | |
|---|---|
|
Version |
Available in Microsoft Windows 8 and later versions of Windows. |
|
Header |
|
|
Library |
|
|
DLL |
|
See also