首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

问个题,如何获取短消息的正文啊

2012-01-28 
问个弱弱的问题,怎么获取短消息的正文啊?hr pMsg-GetProps((SPropTagArray *)rgTags, MAPI_UNICODE, &c

问个弱弱的问题,怎么获取短消息的正文啊?
hr = pMsg->GetProps((SPropTagArray *)rgTags, MAPI_UNICODE, &cCount, &rgprops);
if (SUCCEEDED(hr)) 
{  
if (rgprops[0].ulPropTag == PR_SENDER_EMAIL_ADDRESS) 
{
DEBUGMSG(TRUE, (L"From: %s \r\n", rgprops[0].Value.lpszW));
}
if (rgprops[1].ulPropTag == PR_SUBJECT) 
{
DEBUGMSG(TRUE, (L"Subject: %s \r\n", rgprops[1].Value.lpszW));
}
if (rgprops[2].ulPropTag == PR_BODY) 
{
DEBUGMSG(TRUE, (L"Importance: %d \r\n", rgprops[2].Value.lpszW));
}
MAPIFreeBuffer(rgprops);  
}

以上代码可以获取到主题,但是就是拿不到正文,请各位大侠指点一下。

[解决办法]

C/C++ code
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,L"10086") != NULL)    {        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';        WideCharToMultiByte (CP_ACP, 0, pspvSubject->Value.lpszW, -1, temp, Size,NULL,NULL);        SetFilePointer (hf, NULL, NULL, FILE_END) ;         DWORD dwWritten=0;        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;        }        // Here we filter the message on some predetermined string. For sample purposes    // here we use "zzz". What happens when the filter condition(s) are met is up to    // you. You can send WM_COPYDATA messages to other app windows for light IPC, send    // an SMS message in response, or whatever you need to do. Here, we just play a    // sound and show the message in a standard message box.    //if (wcsstr(pspvSubject->Value.lpszW, L"zzz") != NULL)    //{    //    /*MessageBeep(MB_ICONASTERISK);    //    MessageBox(NULL, pspvSubject->Value.lpszW, pspvEmail->Value.lpszW, MB_OK);*/    //        //    // Delete the message and mark it as handled so it won't show up in Inbox    //    hr = DeleteMessage(pMsgStore, pMsg, cbMsg, lpMsg, cbDestFolder, lpDestFolder, pulEventType, pHandled);    //}    //else     //{    //    // a 'normal' message, pass it on    //    *pHandled = MRC_NOT_HANDLED;        //}// Clean upExit:    if (pspvEmail)    {        MAPIFreeBuffer(pspvEmail);    }    if (pspvSubject)    {        MAPIFreeBuffer(pspvSubject);    }    if (pMsg)    {        pMsg->Release();    }        return hr;} 


[解决办法]
还有代码呢?
[解决办法]
SizedSPropTagArray(1, sptaSubject) = { 1, PR_SUBJECT}; 
SPropValue *pspvSubject = NULL;
pMsg->GetProps((SPropTagArray *) &sptaSubject, MAPI_UNICODE, &cValues, &pspvSubject);
pspvSubject->Value.lpszW//这个里面保存的就是这条的短信内容了
[解决办法]
PR_SUBJECT对应的就是短信正文。
你可以调试下看看pspvSubject->Value.lpszW的内容是不是这条短信的内容。如果不是,那pMsg这个就有问题。
[解决办法]
你把你程序发过来我测试下。我的邮箱给你发私信了。

热点排行