📄 addcallcost.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
////////////////////////////////////////////////////////////////////////////
//
// This is "Sample Code" and is distributable subject to the terms of the end
// user license agreement.
//
/////////////////////////////////////////////////////////////////////////////
/****************************************************************************
This is a sample showing how to use the EDB APIs to add an extra field to the
call log database.
****************************************************************************/
#include "callcost.h"
// Declare global constants
const LPWSTR c_pwszProgramInitSubKey = L"Init";
const LPWSTR c_pwszProgramInitValueName = L"Launch75";
const CEPROPSPEC c_rgCallCostProp =
{
1, // wVersion
LGPID_CALLCOST, // propid
0, // dwFlags
NULL, // pwszPropName
0 // cchPropName
};
// Declare functions needed by WinMain
BOOL AddCallCostProperty();
BOOL UnregisterProgramFromInit();
// **************************************************************************
// Function Name: WinMain
//
// Purpose: Add call cost property to the Call Log database for the phone.
//
// Arguments:
// IN HINSTANCE hInstance - Handle to the current instance of the application
// IN HINSTANCE hPrevInstance - Handle to the previous instance of the application.
// IN LPWSTR lpCmdLine - Pointer to a null-terminated string specifying the command line
// for the application, excluding the program name.
// IN int iCmdShow - Specifies how the window is to be shown.
//
// Return Values:
// BOOL
//
// External Effects:
// Removes program registration from HKLM\Init if successful.
//
// Assumptions:
// Program registration in HKLM\Init is under the value name "Launch75".
BOOL WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int iCmdShow)
{
BOOL fRet = FALSE;
HRESULT hr;
// Open global handle to Call Log database
hr = PhoneOpenCallLog(&g_hCallLog);
if (FAILED(hr))
{
DEBUGMSG(TRUE, (_T("PhoneOpenCallLog failed: (HRESULT)0x%lx.\r\n"), hr));
goto Exit;
}
// Check to see if call cost property already present
fRet = IsCallCostPresent();
if (fRet)
{
DEBUGMSG(TRUE, (_T("Call cost property already present.\r\n")));
}
else
{
// Add call cost property to Call Log database
fRet = AddCallCostProperty();
DEBUGMSG(fRet, (_T("Call cost property added.\r\n")));
}
Exit:
if (fRet)
{
// Unregister this program from being called during boot initialization
if (UnregisterProgramFromInit())
{
DEBUGMSG(TRUE,
(_T("Program unregistered successfully from device initialization.\r\n")));
}
}
// Cleanup
if (INVALID_HANDLE_VALUE != g_hCallLog)
{
PhoneCloseCallLog(g_hCallLog);
}
return fRet;
}
// **************************************************************************
// Function Name: AddCallCostProperty
//
// Purpose: Add call cost property to the Call Log database for the phone.
//
// Arguments:
// N/A
//
// Limitations:
// LG_COUNT_PROPS is not updated after the new property is added.
//
// Return Values:
// BOOL
//
// External Effects:
// Call Log database gains a new property.
//
BOOL AddCallCostProperty()
{
BOOL fRet = FALSE;
CEGUID Guid;
CEOID Oid;
// CeAddDatabaseProps can add the new property but first requires
// the Call Log's CEGUID and CEOID
if (GetCallLogGuid(&Guid) && GetCallLogOid(&Oid))
{
// Close the global Call Log handle to free the Call Log database
PhoneCloseCallLog(g_hCallLog);
// Now add the new call cost property
fRet = CeAddDatabaseProps(&Guid, Oid, 1, (CEPROPSPEC*)&c_rgCallCostProp);
DEBUGMSG(!fRet,
(_T("AddCallCostProperty: CeAddDatabaseProps failed: 0x%lx.\r\n"),
GetLastError()));
// Reopen the global Call Log handle in case any other functions need it
PhoneOpenCallLog(&g_hCallLog);
}
return fRet;
}
// **************************************************************************
// Function Name: UnregisterProgramFromInit
//
// Purpose: Unregister this program from being called by the bootup
// initialization process.
//
// Arguments:
// N/A
//
// Return Values:
// BOOL
//
// External Effects:
// This program will no longer run during bootup initialization.
//
// Assumptions:
// This function can only succeed if the program is registered under a
// value name of "Launch75". In addition, since HKLM\Init is a protected
// registry key, this binary must also be digitally signed.
BOOL UnregisterProgramFromInit()
{
BOOL fRet = FALSE;
HKEY hKey;
LONG lRet;
// Open the HKLM\Init key then delete the value name corresponding to this program.
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_pwszProgramInitSubKey, 0, 0, &hKey);
if (ERROR_SUCCESS == lRet)
{
lRet = RegDeleteValue(hKey, c_pwszProgramInitValueName);
if (ERROR_SUCCESS == lRet)
{
fRet = TRUE;
}
else
{
// This is not an error if the error code is ERROR_FILE_NOT_FOUND
if (ERROR_FILE_NOT_FOUND == lRet)
{
fRet = TRUE;
}
else
{
DEBUGMSG(TRUE,
(_T("UnregisterProgramFromInit: RegDeleteValue failed: 0x%lx.\r\n"),
lRet));
}
}
RegCloseKey(hKey);
}
else
{
DEBUGMSG(TRUE,
(_T("UnregisterProgramFromInit: RegOpenKeyEx failed: 0x%lx.\r\n"),
lRet));
}
return fRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -