handleservice.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 531 行 · 第 1/2 页
CPP
531 行
*/
#if _WIN32_WCE > 0x500
TCHAR szNotificationName[] = TEXT("FunambolPluginCradled");
TCHAR registryName[] = TEXT("System\\State\\Hardware");
TCHAR registryKey[] = TEXT("Cradled");
HRESULT NotifyCradleEvent() {
NOTIFICATIONCONDITION nc;
HRESULT hr = S_OK;
//const wchar_t* programPath= getProgramPath();
const wchar_t* programPath = toWideChar(getRegConfig()->getAppPath().c_str());
if (wcscmp(programPath, L"") == 0) {
LOG.info("Notification cralde event: it is not possible to register the service: path not found: %s", programPath);
return S_FALSE;
}
wstring szAppName(programPath);
szAppName.insert(0,L"\"");
szAppName += L"\\";
szAppName += SYNCAPP;
szAppName += L"\"";
// Receive notifications whenever the Windows Mobile-based 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(HKEY_LOCAL_MACHINE,
registryName,
registryKey,
szNotificationName,
szAppName.c_str(),
NULL,
NULL,
0,
0,
&nc);
if (hr == S_OK) {
LOG.debug("Cradle notification succesfully registered");
} else if (hr == E_ALREADY_REGISTERED) {
LOG.debug("Cradle notification already registered");
} else {
LOG.debug("Cradle notification generic error");
}
if (programPath) {
delete [] programPath;
}
return hr;
}
HRESULT RemoveNotifyCradleEvent() {
HRESULT hr = RegistryStopNotification(szNotificationName);
if (hr == S_OK) {
LOG.debug("Cradle notification succesfully removed");
} else {
LOG.debug("Cradle notification generic error in removing: it cannot be found");
}
return hr;
}
#endif
enum {
eePR_ENTRYID,
eePR_DISPLAY_NAME,
eeNUM_COLS};
// These tags represent the message information we would like to pick up
static SizedSPropTagArray(eeNUM_COLS, Columns) =
{
eeNUM_COLS,
PR_ENTRYID,
PR_DISPLAY_NAME
};
wchar_t* setMailAccountSignature(const char* signature = NULL) {
HRESULT hr;
IMAPISession * pSession = NULL;
IMAPITable* pTable = NULL;
SRowSet* psrs = NULL;
IMsgStore* pStore = NULL;
BOOL accountFound = FALSE;
SPropValue* rgprops = NULL;
wchar_t* ret = NULL;
bool msgset = false;
// First log on to the store.
hr = MAPILogonEx (NULL, NULL, NULL, NULL, &pSession);
EXIT_ON_FAILED (hr);
// Get the message stores table
hr = pSession->GetMsgStoresTable (MAPI_UNICODE, &pTable);
EXIT_ON_FAILED (hr);
hr = pTable->SetColumns((LPSPropTagArray)&Columns, 0);
EXIT_ON_FAILED(hr);
while (!msgset){
// Get a row
hr = pTable->QueryRows (1, 0, &psrs);
EXIT_ON_FAILED (hr);
// Did we hit the end of the table?
if (psrs->cRows != 1) {
break;
}
//
// the display name is the name of the account.
//
wchar_t* displayName = psrs->aRow[0].lpProps[eePR_DISPLAY_NAME].Value.lpszW;
//
// The name of the MessageStore that we use for the own Transport
//
if (wcscmp(displayName, ACCOUNT_NAME) == 0) {
accountFound = TRUE;
// Open this message store
hr = pSession->OpenMsgStore (NULL,
psrs->aRow[0].lpProps[0].Value.bin.cb,
(ENTRYID *) psrs->aRow[0].lpProps[0].Value.
bin.lpb, NULL, 0, &pStore);
EXIT_ON_FAILED (hr);
SPropValue rgprops[3] = {0};
wstring sign = TEXT(FUNAMBOL_SIGNATURE);
if (signature) {
wchar_t* t = toWideChar(signature);
sign = t;
delete [] t;
}
rgprops[0].ulPropTag = PR_CE_SIGNATURE;
rgprops[0].Value.lpszW = (wchar_t*)sign.c_str();
rgprops[1].ulPropTag = PR_CE_USE_SIGNATURE;
rgprops[1].Value.b = true;
rgprops[2].ulPropTag = PR_CE_USE_SIGNATURE_REPLY_FORWARD;
rgprops[2].Value.b = true;
hr = pStore->SetProps(3, rgprops, NULL);
EXIT_ON_FAILED (hr);
}
// Clean up
MAPIFreeBuffer (rgprops);
FreeProws (psrs);
rgprops = NULL;
psrs = NULL;
RELEASE_OBJ (pStore);
}
if (accountFound == FALSE) {
LOG.error("No " PROVIDER " account found");
}
FuncExit:
MAPIFreeBuffer (rgprops);
FreeProws (psrs);
RELEASE_OBJ (pStore);
RELEASE_OBJ (pTable);
RELEASE_OBJ (pSession);
return ret;
}
//-------------------------------------------------------------------------- MAIN
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
int ret = 0;
//MessageBox(NULL, TEXT("Inside"), TEXT("Alert"), MB_OK);
if(wcscmp(lpCmdLine,_T("registerByLink")) == 0) {
//scheduleNextGPRSCheck(0);
//scheduleNextGPRSCheck(CHECK_TIME);
//if (checkGPRS()) {
Sleep(20000);
ret = registerService();
//}
} else if(wcscmp(lpCmdLine,_T("register")) == 0) {
terminateStartsyncProcess();
ret = registerService();
checkGPRS();
//scheduleNextGPRSCheck(CHECK_TIME);
createLink();
} else if(wcscmp(lpCmdLine,_T("deregister")) == 0) {
terminateStartsyncProcess();
deleteLink();
ret = deregister();
//scheduleNextGPRSCheck(0);
} else if(wcscmp(lpCmdLine,_T("createAccount")) == 0) {
terminateStartsyncProcess();
createAccount();
} else if(wcscmp(lpCmdLine,_T("deleteAccount")) == 0) {
terminateStartsyncProcess();
wchar_t* xx = getFunambolGUID();
deleteAccount(xx);
} else if (wcscmp(lpCmdLine, APP_RUN_AT_TIME) == 0) {
/*
HANDLE hMutex;//Handle to mutex...
// Create mutex here
hMutex = CreateMutex(NULL, TRUE, TEXT("checkConnectionInProgress") );
switch(GetLastError()) {
case ERROR_SUCCESS:
break;
case ERROR_ALREADY_EXISTS:
return -2;
default:
return -1;
}
if (checkGPRS()) {
registerService();
}
scheduleNextGPRSCheck(CHECK_TIME);
//CloseHandle( hMutex );
*/
} else if(wcscmp(lpCmdLine,_T("setSignature")) == 0) {
setMailAccountSignature();
}
#if _WIN32_WCE > 0x500
//
// try to get the cradle event only in WM5
//
else if (wcscmp(lpCmdLine, L"registerCradle") == 0) {
NotifyCradleEvent();
} else if (wcscmp(lpCmdLine, L"deregisterCradle") == 0) {
RemoveNotifyCradleEvent();
}
#endif
return ret;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?