Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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:

  1. 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.
  2. Call CreateThreadpoolWork. Provide a callback function that calls CM_Unregister_Notification. Add the returned work structure to the previously allocated context structure.
  3. Call CM_Register_Notification and provide the context structure as the pContext parameter.
  4. Do work, get notifications, etc.
  5. Call SubmitThreadpoolWork from within the notification callback, providing the pointer to a threadpool work structure (PTP_WORK) stored in your context structure.
  6. When the threadpool thread runs, the work item calls CM_Unregister_Notification.
  7. 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.

Caution  Do not free the context structure until after the work item has called CM_Unregister_Notification. You can still receive notifications after submitting the threadpool work item and before the work item calls CM_Unregister_Notification.
 

Requirements

Target platform

Universal

Version

Available in Microsoft Windows 8 and later versions of Windows.

Header

Cfgmgr32.h (include Cfgmgr32.h)

Library

Cfgmgr32.lib;
OneCoreUAP.lib on Windows 10

DLL

CfgMgr32.dll

See also

UnregisterDeviceNotification

 

 

Send comments about this topic to Microsoft

Show: