Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
4/8/2010

An application can use the RegistryNotifyCallbackfunction to register a callback that is called when changes occur in the Bluetoothregistry value under the HKEY_LOCAL_MACHINE\System\State\Hardwarekey. When the state of the Bluetooth radio changes, the callback notifies the caller about the new state. The pConditionparameter points to the NOTIFICATIONCONDITIONstructure that stores the the registration criteria.

For information about the callback prototype, see REGISTRYNOTIFYCALLBACK.

To stop receiving notifications through the callback, call the RegistryCloseNotificationfunction and pass the handle returned by RegistryNotifyCallbackas a parameter.

The following code example shows how to register for notifications using RegistryNotifyCallback.

Note:
Error handling has been omitted in this topic for clarity.
Copy Code
//  FUNCTION: HRESULT RegisterBluetoothCallback()
//  PURPOSE: 
//	- Registers a notification request through callback,
BluetoothStateCallback. 
//	- The callback is called when Bluetooth radio state changes.

HRESULT RegisterBluetoothCallback()
{
  #define SN_BLUETOOTHPOWERBSTATE_ROOT	HKEY_LOCAL_MACHINE
  #define SN_BLUETOOTHPOWERBSTATE_PATH   
TEXT("System\\State\\Hardware")
  #define SN_BLUETOOTHPOWERBSTATE_VALUE   TEXT("Bluetooth")
  #define SN_BLUETOOTHPOWERBSTATE_BITMASK 3

  HRESULT  hr		= NULL;
  NOTIFICATIONCONDITION  nc;
  HREGNOTIFY  g_hNotify_Callback = NULL;   // Handles to
notifications through callback

  nc.ctComparisonType = REG_CT_ANYCHANGE;
  nc.dwMask		 = SN_BLUETOOTHPOWERBSTATE_BITMASK;
  nc.TargetValue.dw   = 0;

   // Register Bluetooth radio state notification.
  hr = RegistryNotifyCallback(
				SN_BLUETOOTHPOWERBSTATE_ROOT,
				SN_BLUETOOTHPOWERBSTATE_PATH,
				SN_BLUETOOTHPOWERBSTATE_VALUE,
				BluetoothStateCallback, 	// This
notification uses a callback.
				0,  
				&nc,
				&g_hNotify_Callback
				);

  if (FAILED(hr))
  {
	perform error handling;
	return hr;
  }
  return S_OK;
}

See Also