Windows/MFC

how to retrive SMS and Email in pocket pc 2005

aucd29 2013. 10. 2. 18:23
http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/60045e0b-2d5b-419d-a3ff-9ee1ec5e867c

You can use MAPI to retrive email and SMS information. First , we should understand message store concept. Base on my understanding, Message stores do correspond to message account. The default message store (Microsoft? ActiveSync?) is present by default, but additional message stores can be added by the user (through Inbox or another e-mail application) or from the installation of a MAPI Service Provider. If device support sms, it will also include SMS message stores named "SMS".

Each Message Store contains one or more folders. Some folders have unique identifiers defined to make finding the folders easier. In particular, the "Inbox" has the identifier PR_CE_IPM_INBOX_ENTRYID. The "Outbox" has the identifier PR_CE_IPM_DRAFTS_ENTRYID (defined in CEMAPI.H).

Below is a sample , how to read every message store and its folders.


Code Snippet

[code]
void CMAPI6TestDlg::OnBnClickedButton1()
{
    HRESULT hr;
    ICEMAPISession * pSession = NULL;
    SRowSet * pRows = NULL;
    IMsgStore * pStore = NULL;

    hr = MAPIInitialize(NULL);
    if (hr != S_OK) {
        // MAPIInitialize failed.
        AfxMessageBox(L"error");
    }

    hr = MAPILogonEx(0, NULL, NULL, 0, (LPMAPISESSION *)&pSession);
    if (hr != S_OK) {
        AfxMessageBox(L"error");
    }

    IMAPITable *ptable;
    hr=pSession->GetMsgStoresTable(0,&ptable);

    enum{
        ePR_DISPLAY_NAME,
        ePR_ENTRYID,//ePR_CE_UNIQUE_STORE_ID,
        NUM_COLS
    };

    SizedSPropTagArray(NUM_COLS,Columns) =
    {
        NUM_COLS,
        PR_DISPLAY_NAME,
        PR_ENTRYID,
    };

    hr= ptable->SetColumns((LPSPropTagArray)&Columns,0);

    LPENTRYID pEntryId = NULL;
    ULONG cbEntryId = 0;
    IMAPIFolder *pFolder;
    ULONG ulObjType = 0;
    IMAPITable *ptbl;
    SRowSet *prowset = NULL;

    static const SizedSSortOrderSet(1, sortOrderSet) = { 1, 0, 0, { PR_MESSAGE_DELIVERY_TIME, TABLE_SORT_DESCEND } };
    static const SizedSPropTagArray (3, spta) = { 3, PR_SENDER_NAME,PR_SUBJECT,PR_MESSAGE_DELIVERY_TIME };

    while(SUCCEEDED(ptable->QueryRows(1, 0,&pRows)))
    {
        if(pRows->cRows==0)
            return;

        //Read message store name
        TCHAR *pszStoreName =pRows->aRow[0].lpProps[0].Value.lpszW;

        //get activesync store,email store is 0 index
        hr = pSession->OpenMsgStore(0,
                                    pRows->aRow[0].lpProps[1].Value.bin.cb,
                                    (ENTRYID *)pRows->aRow[0].lpProps[1].Value.bin.lpb,
                                    NULL,
                                    0,
                                    &pStore);

        //Read folder
        LPSPropValue rgprops=NULL;
        ULONG cValues;
        ULONG rgTag[]={1,PR_CE_IPM_DRAFTS_ENTRYID}; //You can read any folder with its name tag

        hr = pStore->GetProps((LPSPropTagArray)rgTag,MAPI_UNICODE,&cValues,&rgprops);
        hr = pStore->OpenEntry(rgprops->Value.bin.cb, (LPENTRYID)rgprops->Value.bin.lpb, NULL, 0, &ulObjType, (LPUNKNOWN*)&pFolder);
        hr = pFolder->GetContentsTable(0, &ptbl);
        hr = ptbl->SortTable((SSortOrderSet *)&sortOrderSet, 0);
        hr = ptbl->SetColumns ((SPropTagArray *) &spta, 0);

        // iterate through each message in the table
        while (TRUE)
        {
            // Free the previous row
            FreeProws (prowset);
            prowset = NULL;
            hr = ptbl->QueryRows (1, 0, &prowset);

            if ((hr != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
                break;

            ASSERT (prowset->aRow[0].cValues == spta.cValues);
            SPropValue *pval = prowset->aRow[0].lpProps;

            //Read Email filed value, which is correspond with spta
            LPCTSTR pszSender = pval[0].Value.lpszW;
            LPCTSTR pszSubject = pval[1].Value.lpszW;
            LPCTSTR time=pval[2].Value.lpszW;        
        }
    }

    //Release
    FreeProws(pRows);
    ptbl->Release();
    ptbl=NULL;
    pFolder->Release();
    pFolder=NULL;
    pStore->Release();
    pStore=NULL;
}
[/code]

Best regards,
Guang-Ming Bian - MSFT