I'm facing with problem working through MAPI. When I obtain list of messages from any folder I get empty list. I do the following steps:
1. Open MAPI session
2. Invoke OpenMsgStore
3. Get folder identifier using PR_CE_IPM_DRAFTS_ENTRYID
4. Do OpenEntry
5. Obtain message list using GetContentsTable
6. And at last do the following:
status = pFolderItems->QueryRows (1, 0, &pRowSetMsg);
if ((status != S_OK) || (pRowSetMsg == NULL) || (pRowSetMsg->cRows == 0))
{
// each time we reach this place because pRowSetMsg->cRows equals to 0
// but there's at least one message in the folder (I put it by myself)
}
Each operation from above returns S_OK.
This is code snippet:
// Log onto MAPI
status = MAPILogonEx(0, NULL, NULL, 0, static_cast<LPMAPISESSION *>(&pSession));
HALT_ON_ERROR(status); // HALT_ON_ERROR will goto Error if FAILED(status)
// Get the table of accounts
status= pSession->GetMsgStoresTable(0, &ptbl);
HALT_ON_ERROR(status);
// set the columns of the table we will query
status= ptbl->SetColumns ((SPropTagArray *) &spta, 0);
HALT_ON_ERROR(status);
while (TRUE) {
// Free the previous row
FreeProws (prowset);
prowset = NULL;
// get item
status = ptbl->QueryRows (1, 0, &prowset);
if ((status != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
{
break;
}
ASSERT (prowset->aRow[0].cValues == spta.cValues);
pval = prowset->aRow[0].lpProps;
ASSERT (pval[0].ulPropTag == PR_DISPLAY_NAME);
//MessageBox(NULL, pval[0].Value.lpszW, TEXT("Message Store"), MB_OK);
enum {EID, NAME, NUM_COLS};
// Open the first returned (default) message store
status= pSession->OpenMsgStore(
NULL,//Window handle for dialogs
prowset->aRow[0].lpProps[EID].Value.bin.cb,//size and...
(LPENTRYID)prowset->aRow[0].lpProps[EID].Value.bin.lpb,//value of entry to open
NULL,//Use default interface (IMsgStore) to open store
MAPI_BEST_ACCESS,//Flags
&lpTempMDB);//Pointer to place the store in
HALT_ON_ERROR(status);
// ULONG rgTags[] = { 1, PR_CE_IPM_INBOX_ENTRYID }; // inbox
ULONG rgTags[] = { 1, PR_CE_IPM_DRAFTS_ENTRYID }; // draft
// ULONG rgTags[] = { 1, PR_IPM_OUTBOX_ENTRYID }; // outbox
status = lpTempMDB->GetProps((SPropTagArray *)rgTags, 0L, &cValues, &rgprops);
HALT_ON_ERROR(status);
// get folder
status = lpTempMDB->OpenEntry(
rgprops[0].Value.bin.cb,
(LPENTRYID)rgprops[0].Value.bin.lpb,
NULL, //We want the default interface (IMAPIFolder)
MAPI_BEST_ACCESS, //Flags
&ulObjType, //Object returned type
(LPUNKNOWN *) &lpTempFolder); //Returned folder
HALT_ON_ERROR(status);
// get folder content
status = lpTempFolder->GetContentsTable(0L, &pFolderItems);
HALT_ON_ERROR(status);
while (TRUE) {
FreeProws (pRowSetMsg);
status = pFolderItems->QueryRows (1, 0, &pRowSetMsg);
if ((status != S_OK) || (pRowSetMsg == NULL) || (pRowSetMsg->cRows == 0))
{
break;
}
pval = pRowSetMsg->aRow[0].lpProps;
MessageBox(NULL, pval[0].Value.lpszW, TEXT("Message Item"), MB_OK);
}
}
pSession->Logoff(0, 0, 0);
Error:
FreeProws (prowset);
Any ideas why it returns empty list?