_Examining Extended MAPI 1.0_
by Les Thaler

Listing One
LPMAPISESSION pSession;
HRESULT       hRes;
if (FAILED(hRes = MAPIInitialize(NULL)))
    return hRes;
if (FAILED(hRes = MAPILogonEx((ULONG)hWnd,NULL,NULL,LOGON_FLAGS,&pSession)))
    DoError();
// Call methods on session object to get other interfaces
hRes = pSession -> OpenEntry(...);
 . . .

Listing Two
HRESULT       hRes;
LPSPropValue  pspv;
ULONG         ulCnt; 
LPMESSAGE     pMsg = ...// code to get message object    

SizedSPropTagArray(2,spt) = {2, {PR_SUBJECT, PR_BODY}};

hRes = pMsg -> GetProps((LPSPropTagArray) &spt, 0, &ulCnt, &pspv);
if (S_OK != hRes || !ulCnt)
{
    hRes = MAPI_E_NOT_FOUND;
    DoError();
}
cout << "Subject: " << pspv[0].Value.lpszA << endl;
cout << "Body: " << pspv[1].Value.lpszA << endl;

MAPIFreeBuffer(pspv);
 . . .

Listing Three
SPropValue spv[2];

spv[0].ulPropTag = PR_SUBJECT;
spv[0].Value.lpszA = "Miles Davis";
spv[1].ulPropTag = PR_BODY;
spv[1].Value.lpszA = "A tribute to Jack Johnson";

hRes = pMsg -> SetProps(2,spv,NULL);

if (FAILED(hRes))
    DoError();
hRes = pMsg -> SaveChanges(0);
pOrigMsg -> Release();
 . . .

Listing Four
HRESULT         hRes;
LPSRowSet       pRows = NULL;
SRestriction    sres;
SPropValue      spv;
LPMAPIFOLDER    pFldr;
LPMAPITABLE     pCTbl;

SizedSPropTagArray(2,spt) = {2, PR_NORMALIZED_SUBJECT, PR_MESSAGE_SIZE};
SizedSSortOrderSet(2,sso) = {2,0,0, PR_SUBJECT,TABLE_SORT_ASCEND,
                             PR_MESSAGE_SIZE,TABLE_SORT_DESCEND};
hRes = pFldr -> GetContentsTable(0,&pCTbl);
// select columns first
hRes = pCTbl->SetColumns((LPSPropTagArray)&spt,0);    
// sort depends on result of Restrict, do first
sres.rt = RES_PROPERTY;
sres.res.resProperty.relop = RELOP_GT;
sres.res.resProperty.ulPropTag = PR_MESSAGE_SIZE;
sres.res.resProperty.lpProp = &spv;

spv.ulPropTag = PR_MESSAGE_SIZE;
spv.Value.l   = 1024;

hRes = pCTbl->Restrict(&sres,TBL_BATCH);

// sort
hRes = pCTbl->SortTable((LPSSortOrderSet) & sso,0);    

// execute query
hRes = pCTbl->QueryRows(100,0,&pRows);
{
    // do something with the rows
}
FreeProws(pRows);
pCTbl -> Release();
pFldr -> Release();
 . . .


2



