// The notification name must be unique across the mobile device.
// It is considered good practice to prefix this name with the name of your application.
TCHAR szNotificationName[] = TEXT("myAppCradled");
TCHAR szAppName[] = TEXT("myApp.exe param1 param2");
// Receive notifications whenever the mobile device is cradled.
nc.ctComparisonType = REG_CT_EQUAL;
nc.TargetValue.dw = 1;
// Since you are not masking, dwMask must be non-zero for dwords.
nc.dwMask = 0xFFFFFFFF;
// The application is launched from the command line with: myApp.exe param1 param2 /notify "myAppCradled".
hr = RegistryNotifyApp(SN_CRADLEPRESENT_ROOT,
SN_CRADLEPRESENT_PATH,
SN_CRADLEPRESENT_VALUE,
szNotificationName,
szAppName,
NULL,
NULL,
0,
0,
&nc);
// When you are done, call RegistryStopNotification to remove the notification.
// hr = RegistryStopNotification(szNotificationName);
return hr;
}
这里的SN_CRADLEPRESENT_ROOT, path, value这些参数估计都要改掉
在snapi.h里面有这个定义
////////////////////////////////////////////////////////////////////////////////
// HeadsetPresent
// Gets a value indicating whether a headset is present
#define SN_HEADSETPRESENT_ROOT HKEY_LOCAL_MACHINE
#define SN_HEADSETPRESENT_PATH TEXT("System\\State\\Hardware")
#define SN_HEADSETPRESENT_VALUE TEXT("Headset")