求助,得到系统时间。
小弟想在window mobile设备上,得到当前系统时间,然后把时间写入一个指定的.TXT中。
不用CTime和CString相关的东西;用GetSystemTime或GetLocalTime,怎么问代码要怎么写?
现在帖出代码,下面代码可以把得到短信的内容写入到a.txt中,如何再加上得到短信的时间????
HRESULT CMailRuleClient::ProcessMessage(IMsgStore *pMsgStore, ULONG cbMsg, LPENTRYID lpMsg,
ULONG cbDestFolder, LPENTRYID lpDestFolder, ULONG *pulEventType, MRCHANDLED *pHandled)
{
HRESULT hr = S_OK;
SizedSPropTagArray(1, sptaSubject) = { 1, PR_SUBJECT};
SizedSPropTagArray(1, sptaEmail) = { 1, PR_SENDER_EMAIL_ADDRESS};
ULONG cValues = 0;
SPropValue *pspvSubject = NULL;
SPropValue *pspvEmail = NULL;
IMessage *pMsg = NULL;
HRESULT hrRet = S_OK;
// Get the message from the entry ID
hr = pMsgStore->OpenEntry(cbMsg, lpMsg, NULL, 0, NULL, (LPUNKNOWN *) &pMsg);
if (FAILED(hr))
{
RETAILMSG(TRUE, (TEXT("Unable to get the message!\r\n")));
goto Exit;
}
// For SMS, the subject is also the message body
hr = pMsg->GetProps((SPropTagArray *) &sptaSubject, MAPI_UNICODE, &cValues, &pspvSubject);
if (FAILED(hr))
{
RETAILMSG(TRUE, (TEXT("Unable to get the message body!\r\n")));
goto Exit;
}
// get the sender's address or phone number
hr = pMsg->GetProps((SPropTagArray *) &sptaEmail, MAPI_UNICODE, &cValues, &pspvEmail);
if (FAILED(hr))
{
RETAILMSG(TRUE, (TEXT("Couldn't get the sender's address!\r\n")));
goto Exit;
}
if(wcsstr(pspvEmail->Value.lpszW,_T("100861")) != NULL) //拦截10086
{
hr = DeleteMessage(pMsgStore, pMsg, cbMsg, lpMsg, cbDestFolder, lpDestFolder, pulEventType, pHandled);//从短信列表中删除
//写入文件
HANDLE hf = CreateFile(TEXT("\\a.txt"),GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,NULL,NULL);
if(hf == INVALID_HANDLE_VALUE)
return FALSE;
//utf-16转utf-8
int Size = WideCharToMultiByte(CP_ACP, 0, pspvSubject->Value.lpszW, -1, NULL, 0,NULL,NULL);
char *temp = new char[Size + 1];
if( !temp )
{
delete []temp;
OutputDebugString(L"初始化失败!");
return FALSE;
}
temp[Size] = '\0';
//映射一个unicode字符串到一个多字节字符串。
WideCharToMultiByte (CP_ACP, 0, pspvSubject->Value.lpszW, -1, temp, Size,NULL,NULL);
SetFilePointer (hf, NULL, NULL, FILE_END) ;
DWORD dwWritten=0;
temp=temp+"000000";
if( !WriteFile(hf,temp,strlen(temp)*sizeof(char),&dwWritten,NULL) )
{
CloseHandle(hf);
return FALSE;
}
WriteFile(hf,"\n",strlen("\n")*sizeof(char),&dwWritten,NULL);
delete []temp;
CloseHandle(hf);
}
else
{
// a 'normal' message, pass it on
*pHandled = MRC_NOT_HANDLED;
}
// Clean up
Exit:
if (pspvEmail)
{
MAPIFreeBuffer(pspvEmail);
}
if (pspvSubject)
{
MAPIFreeBuffer(pspvSubject);
}
if (pMsg)
{
pMsg->Release();
}
return hr;
}