Microsoft KB Archive/174394: Difference between revisions
(importing KB archive) |
m (Text replacement - "&" to "&") |
||
(3 intermediate revisions by the same user not shown) | |||
Line 84: | Line 84: | ||
=== Sample Code === | === Sample Code === | ||
<pre class="codesample"> #include | <pre class="codesample"> #include <mapiutil.h> | ||
#include | #include <stdio.h> | ||
void _FreeRowSet( LPSRowSet ); | void _FreeRowSet( LPSRowSet ); | ||
Line 92: | Line 92: | ||
void main ( void ) | void main ( void ) | ||
{ | { | ||
printf ( | printf ( "**** Begin program ****\r\n" ); | ||
HRESULT hResult = 0; | HRESULT hResult = 0; | ||
Line 101: | Line 101: | ||
LPADRLIST lpadrlist = NULL; | LPADRLIST lpadrlist = NULL; | ||
printf ( | printf ( "1. Initializing MAPI..." ); | ||
{ | { | ||
if ( FAILED(hResult = MAPIInitialize( NULL ))) | if ( FAILED(hResult = MAPIInitialize( NULL ))) | ||
{ | { | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
goto error; | goto error; | ||
} | } | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
} | } | ||
printf ( | printf ( "2. Logging on..."); | ||
{ | { | ||
ULONG ulFlags = 0; | ULONG ulFlags = 0; | ||
Line 121: | Line 121: | ||
if( FAILED(hResult = MAPILogonEx( 0, NULL, | if( FAILED(hResult = MAPILogonEx( 0, NULL, | ||
NULL, ulFlags, | NULL, ulFlags, | ||
(LPMAPISESSION FAR *) & | (LPMAPISESSION FAR *) &lpSession ))) | ||
{ | { | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
goto error; | goto error; | ||
} | } | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
} | } | ||
printf ( | printf ("3. Opening Address Book..."); | ||
{ | { | ||
if( FAILED(hResult = lpSession- | if( FAILED(hResult = lpSession-<OpenAddressBook( 0, | ||
NULL, 0, & | NULL, 0, &lpAdrBook ))) | ||
{ | { | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
goto error; | goto error; | ||
} | } | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
} | } | ||
printf ( | printf ("4. Display AddressBook dialog box with one well..." ); | ||
{ | { | ||
LPSTR rglpszDestTitles[1]; | LPSTR rglpszDestTitles[1]; | ||
Line 151: | Line 151: | ||
ulFlags = ulFlags | DIALOG_MODAL; | ulFlags = ulFlags | DIALOG_MODAL; | ||
rglpszDestTitles[0] = | rglpszDestTitles[0] = "To"; | ||
rgulDestComps[0] = MAPI_TO; | rgulDestComps[0] = MAPI_TO; | ||
Line 164: | Line 164: | ||
adrparm.lpfnDismiss = NULL; | adrparm.lpfnDismiss = NULL; | ||
adrparm.lpvDismissContext = NULL; | adrparm.lpvDismissContext = NULL; | ||
adrparm.lpszCaption = | adrparm.lpszCaption = "MAPI ITP tests Address 1"; | ||
adrparm.lpszNewEntryTitle = | adrparm.lpszNewEntryTitle = "For this test dialog"; | ||
adrparm.lpszDestWellsTitle = | adrparm.lpszDestWellsTitle = "Selected Recipients:"; | ||
adrparm.cDestFields = 1; | adrparm.cDestFields = 1; | ||
adrparm.nDestFieldFocus = 0; | adrparm.nDestFieldFocus = 0; | ||
Line 174: | Line 174: | ||
adrparm.lpHierRestriction = NULL; | adrparm.lpHierRestriction = NULL; | ||
if( FAILED(hResult = lpAdrBook- | if( FAILED(hResult = lpAdrBook->Address( &ulUIParam, | ||
& | &adrparm, &lpadrlist ))) | ||
{ | { | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
goto error; | goto error; | ||
} | } | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
} | } | ||
Line 187: | Line 187: | ||
goto error; | goto error; | ||
printf ( | printf ( "5. Getting Entry IDs and opening each " ); | ||
printf ( | printf ( "ADRENTRY...\r\n" ); | ||
{ | { | ||
ULONG cEntry = 0; | ULONG cEntry = 0; | ||
ULONG cProp = 0; | ULONG cProp = 0; | ||
for(cEntry=0; cEntry | for(cEntry=0; cEntry<lpadrlist->cEntries; cEntry++) | ||
{ | { | ||
for(cProp=0; | for(cProp=0; | ||
cProp | cProp < lpadrlist->aEntries[cEntry].cValues; | ||
cProp++) | cProp++) | ||
{ | { | ||
printf ( | printf ( " >Name: " ); | ||
if( lpadrlist- | if( lpadrlist->aEntries[cEntry].rgPropVals[cProp].ulPropTag | ||
== PR_DISPLAY_NAME ) | == PR_DISPLAY_NAME ) | ||
{ | { | ||
printf ( | printf ( | ||
lpadrlist- | lpadrlist->aEntries[cEntry].rgPropVals[cProp].Value.LPSZ | ||
); | ); | ||
printf ( | printf ( " ...\r\n" ); | ||
break; | break; | ||
} | } | ||
} | } | ||
printf ( | printf ( " -->Find EntryID " ); | ||
LPSPropValue lpsPropVal = NULL; | LPSPropValue lpsPropVal = NULL; | ||
lpsPropVal = PpropFindProp ( | lpsPropVal = PpropFindProp ( | ||
lpadrlist- | lpadrlist->aEntries[cEntry].rgPropVals, | ||
lpadrlist- | lpadrlist->aEntries[cEntry].cValues, | ||
PR_ENTRYID ); | PR_ENTRYID ); | ||
if (NULL == lpsPropVal) | if (NULL == lpsPropVal) | ||
printf ( | printf ( " FAILED\r\n " ); | ||
else | else | ||
printf ( | printf ( " OK ... \r\n" ); | ||
printf ( | printf ( " -->OpenEntry " ); | ||
{ | { | ||
ULONG ulObjType = 0; | ULONG ulObjType = 0; | ||
Line 232: | Line 232: | ||
if( FAILED(hResult = | if( FAILED(hResult = | ||
lpAdrBook- | lpAdrBook->OpenEntry(lpsPropVal->Value.bin.cb, | ||
(LPENTRYID)lpsPropVal- | (LPENTRYID)lpsPropVal->Value.bin.lpb, | ||
NULL, ulFlags, & | NULL, ulFlags, &ulObjType, | ||
(LPUNKNOWN*)& | (LPUNKNOWN*)&lpEntry))) | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
else | else | ||
{ | { | ||
printf ( | printf ( " OK\r\n" ); | ||
lpEntry- | lpEntry->Release(); | ||
} | } | ||
} | } | ||
Line 248: | Line 248: | ||
} | } | ||
printf ( | printf ( "6. Opening Default Message Store ... " ); | ||
{ | { | ||
if (FAILED(hResult = OpenDefStore(lpSession, & | if (FAILED(hResult = OpenDefStore(lpSession, &lpMsgStore))) | ||
{ | { | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
goto error; | goto error; | ||
} | } | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
} | } | ||
printf ( | printf ( "7a. Get Receive Folder... " ); | ||
{ | { | ||
SBinary sbInboxEID = {0, NULL}; | SBinary sbInboxEID = {0, NULL}; | ||
Line 265: | Line 265: | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpMsgStore- | lpMsgStore->GetReceiveFolder("IPM.Note", 0, | ||
& | &sbInboxEID.cb, | ||
(LPENTRYID *) & | (LPENTRYID *) &sbInboxEID.lpb, NULL))) | ||
{ | { | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult ); | ||
goto error; | goto error; | ||
} | } | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
printf ( | printf ( "7b. OpenEntry on Inbox[ASCII 133] " ); | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpSession- | lpSession->OpenEntry(sbInboxEID.cb, | ||
(LPENTRYID) sbInboxEID.lpb, NULL, | (LPENTRYID) sbInboxEID.lpb, NULL, | ||
MAPI_MODIFY, & | MAPI_MODIFY, &ulObjType, | ||
(LPUNKNOWN *) & | (LPUNKNOWN *) &lpInbox))) | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult); | ||
else | else | ||
printf ( | printf ( " Open Inbox OK\r\n", hResult); | ||
if (sbInboxEID.cb) | if (sbInboxEID.cb) | ||
Line 292: | Line 292: | ||
} | } | ||
printf ( | printf ( "8. Creating Message... " ); | ||
{ | { | ||
LPMESSAGE lpMsg = NULL; | LPMESSAGE lpMsg = NULL; | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpInbox- | lpInbox->CreateMessage(NULL, 0, &lpMsg))) | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult); | ||
else | else | ||
printf ( | printf ( " OK\r\n" ); | ||
if (lpMsg) | if (lpMsg) | ||
{ | { | ||
printf ( | printf ( "9. Modify Recipients... " ); | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpMsg- | lpMsg->ModifyRecipients(MODRECIP_ADD, lpadrlist))) | ||
printf( | printf( " FAILED with error: %X\r\n", hResult); | ||
else | else | ||
{ | { | ||
printf( | printf( " OK\r\n"); | ||
printf ( | printf ( "10. Get Recipient table... " ); | ||
LPMAPITABLE lpRecips = NULL; | LPMAPITABLE lpRecips = NULL; | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpMsg- | lpMsg->GetRecipientTable(0, &lpRecips))) | ||
printf ( | printf ( " FAILED with error: %X\r\n", hResult); | ||
else | else | ||
{ | { | ||
printf ( | printf ( " OK\r\n" ); | ||
printf ( | printf ( "11. GetRowCount... " ); | ||
LPSRowSet lpsRowSet = NULL; | LPSRowSet lpsRowSet = NULL; | ||
ULONG uRowCnt = 0; | ULONG uRowCnt = 0; | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpRecips- | lpRecips->GetRowCount(0, &uRowCnt))) | ||
printf ( | printf (" FAILED with error: %X\r\n", hResult); | ||
else | else | ||
printf ( | printf (" OK with Count: %u\r\n", uRowCnt ); | ||
printf ( | printf ("13. Getting Entry IDs/OpenEntry...\r\n"); | ||
for (ULONG uRows=0; uRows | for (ULONG uRows=0; uRows < uRowCnt; uRows++) | ||
{ | { | ||
printf ( | printf ( " >QueryRows... " ); | ||
if (FAILED(hResult = | if (FAILED(hResult = | ||
lpRecips- | lpRecips->QueryRows( (ULONG)1, 0, &lpsRowSet))) | ||
printf ( | printf (" FAILED with error: %X\r\n", hResult); | ||
else | else | ||
{ | { | ||
printf ( | printf (" OK\r\n" ); | ||
LPSPropValue lpsPropVal1 = NULL; | LPSPropValue lpsPropVal1 = NULL; | ||
lpsPropVal1 = PpropFindProp ( | lpsPropVal1 = PpropFindProp ( | ||
lpsRowSet- | lpsRowSet->aRow[0].lpProps, | ||
lpsRowSet- | lpsRowSet->aRow[0].cValues, | ||
PR_DISPLAY_NAME ); | PR_DISPLAY_NAME ); | ||
if (NULL != lpsPropVal1) | if (NULL != lpsPropVal1) | ||
{ | { | ||
printf( | printf( " -->Name: " ); | ||
printf( lpsPropVal1- | printf( lpsPropVal1->Value.LPSZ ); | ||
printf( | printf( "\r\n" ); | ||
} | } | ||
printf ( | printf ( " ----->Find EntryID..." ); | ||
LPSPropValue lpsPropVal = NULL; | LPSPropValue lpsPropVal = NULL; | ||
lpsPropVal = PpropFindProp ( | lpsPropVal = PpropFindProp ( | ||
lpsRowSet- | lpsRowSet->aRow[0].lpProps, | ||
lpsRowSet- | lpsRowSet->aRow[0].cValues, | ||
PR_ENTRYID ); | PR_ENTRYID ); | ||
if (NULL == lpsPropVal) | if (NULL == lpsPropVal) | ||
printf ( | printf ( " FAILED\r\n" ); | ||
else | else | ||
{ | { | ||
printf ( | printf ( " OK \r\n" ); | ||
ULONG ulObjType = 0; | ULONG ulObjType = 0; | ||
Line 372: | Line 372: | ||
ulFlags = ulFlags | MAPI_BEST_ACCESS; | ulFlags = ulFlags | MAPI_BEST_ACCESS; | ||
printf ( | printf ( " ----->OpenEntry..."); | ||
if ( FAILED(hResult = | if ( FAILED(hResult = | ||
lpAdrBook- | lpAdrBook->OpenEntry( | ||
lpsPropVal- | lpsPropVal->Value.bin.cb, | ||
(LPENTRYID)lpsPropVal- | (LPENTRYID)lpsPropVal->Value.bin.lpb, | ||
NULL, ulFlags, & | NULL, ulFlags, &ulObjType, | ||
(LPUNKNOWN*)& | (LPUNKNOWN*)&lpEntry))) | ||
printf ( | printf ( " FAILED with error: %X\r\n", | ||
hResult ); | hResult ); | ||
else | else | ||
{ | { | ||
printf ( | printf ( " OK\r\n" ); | ||
lpEntry- | lpEntry->Release(); | ||
} | } | ||
Line 394: | Line 394: | ||
} | } | ||
lpRecips- | lpRecips->Release(); | ||
} | } | ||
} | } | ||
lpMsg- | lpMsg->Release(); | ||
} | } | ||
Line 407: | Line 407: | ||
error: | error: | ||
if (lpInbox) | if (lpInbox) | ||
lpInbox- | lpInbox->Release(); | ||
if (lpMsgStore) | if (lpMsgStore) | ||
{ | { | ||
ULONG uflags = 0; | ULONG uflags = 0; | ||
lpMsgStore- | lpMsgStore->StoreLogoff(&uflags); | ||
lpMsgStore- | lpMsgStore->Release(); | ||
} | } | ||
Line 420: | Line 420: | ||
if (lpAdrBook) | if (lpAdrBook) | ||
lpAdrBook- | lpAdrBook->Release(); | ||
if (lpSession) | if (lpSession) | ||
{ | { | ||
lpSession- | lpSession->Logoff(0,0,0); | ||
lpSession- | lpSession->Release(); | ||
} | } | ||
printf ( | printf ( "***** END PROGRAM *****\r\n" ); | ||
return; | return; | ||
Line 439: | Line 439: | ||
return; | return; | ||
for( cRows = 0; cRows | for( cRows = 0; cRows < lpRows->cRows; ++cRows ) | ||
{ | { | ||
MAPIFreeBuffer( lpRows- | MAPIFreeBuffer( lpRows->aRow[cRows].lpProps ); | ||
} | } | ||
Line 459: | Line 459: | ||
{2,PR_ENTRYID,PR_DEFAULT_STORE}; | {2,PR_ENTRYID,PR_DEFAULT_STORE}; | ||
if (FAILED(hRes = m_pSess - | if (FAILED(hRes = m_pSess -> GetMsgStoresTable(0, &pStoresTbl))) | ||
{ | { | ||
goto Quit; | goto Quit; | ||
Line 467: | Line 467: | ||
sres.res.resProperty.relop = RELOP_EQ; | sres.res.resProperty.relop = RELOP_EQ; | ||
sres.res.resProperty.ulPropTag = PR_DEFAULT_STORE; | sres.res.resProperty.ulPropTag = PR_DEFAULT_STORE; | ||
sres.res.resProperty.lpProp = & | sres.res.resProperty.lpProp = &spv; | ||
spv.ulPropTag = PR_DEFAULT_STORE; | spv.ulPropTag = PR_DEFAULT_STORE; | ||
Line 473: | Line 473: | ||
if (FAILED(hRes = HrQueryAllRows(pStoresTbl, | if (FAILED(hRes = HrQueryAllRows(pStoresTbl, | ||
(LPSPropTagArray) & | (LPSPropTagArray) &sptCols, | ||
& | &sres, NULL, 0, &pRow))) | ||
goto Quit; | goto Quit; | ||
if (pRow & | if (pRow && | ||
pRow - | pRow -> cRows && | ||
pRow - | pRow -> aRow[0].cValues && | ||
PR_ENTRYID == pRow - | PR_ENTRYID == pRow -> aRow[0].lpProps[0].ulPropTag) | ||
sbEID = pRow - | sbEID = pRow -> aRow[0].lpProps[0].Value.bin; | ||
else | else | ||
Line 490: | Line 490: | ||
if (FAILED(hRes = | if (FAILED(hRes = | ||
m_pSess - | m_pSess -> OpenMsgStore(0, sbEID.cb, | ||
(LPENTRYID)sbEID.lpb, | (LPENTRYID)sbEID.lpb, | ||
NULL, MDB_WRITE, m_pMDB))) | NULL, MDB_WRITE, m_pMDB))) | ||
Line 499: | Line 499: | ||
if (pStoresTbl) | if (pStoresTbl) | ||
pStoresTbl - | pStoresTbl -> Release(); | ||
return hRes; | return hRes; | ||
Line 514: | Line 514: | ||
* Abview.cli available from the [ftp://ftp.microsoft.com/developr/mapi/samples/mfcapps/mfcapps.zip Microsoft FTP site] | * Abview.cli available from the [ftp://ftp.microsoft.com/developr/mapi/samples/mfcapps/mfcapps.zip Microsoft FTP site] | ||
* | * "HelloMAPI" (from the Companion CD of the book ''Inside MAPI'') | ||
Latest revision as of 12:30, 21 July 2020
Article ID: 174394
Article Last Modified on 8/18/2005
APPLIES TO
- Microsoft Messaging Application Programming Interface
This article was previously published under Q174394
SYMPTOMS
If you attempt to use the PR_ENTRYID property for Outlook Contacts returned by IAdrBook::Address(), IAdrBook::OpenEntry() will fail with the error code MAPI_E_UNKNOWN_ENTRYID.
CAUSE
This problem occurs because the message store containing the contacts returned has not been opened.
RESOLUTION
There are two workarounds for this problem:
- Open the message store containing the contacts before calling IAdrBook::Address(). In the MORE INFORMATION section, if you move step #6 (open the default message store) before step #3 (opening the address book), then the problem will no longer occur.
- Create a message and add the recipients returned from the IAdrBook::Address() call to the message using these steps.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
The following code both reproduces the problem and demonstrates the workaround described in the Resolution section of this article.
Steps to Reproduce Behavior
- Create a Console Application containing a program with code shown in step 3.
- Add Mapi32.lib to the Object/Library modules text box in the Link tab of the Project Settings dialog box.
- Compile, link, and run the application. When prompted to choose recipients, be sure to select some recipients from your Outlook Address Book in order to reproduce the problem.
Sample Code
#include <mapiutil.h> #include <stdio.h> void _FreeRowSet( LPSRowSet ); HRESULT OpenDefStore( LPMAPISESSION, LPMDB* ); void main ( void ) { printf ( "**** Begin program ****\r\n" ); HRESULT hResult = 0; LPMAPISESSION lpSession = NULL; LPMDB lpMsgStore = NULL; LPMAPIFOLDER lpInbox = NULL; LPADRBOOK lpAdrBook = NULL; LPADRLIST lpadrlist = NULL; printf ( "1. Initializing MAPI..." ); { if ( FAILED(hResult = MAPIInitialize( NULL ))) { printf ( " FAILED with error: %X\r\n", hResult ); goto error; } else printf ( " OK\r\n" ); } printf ( "2. Logging on..."); { ULONG ulFlags = 0; ulFlags = ulFlags | MAPI_LOGON_UI | MAPI_NO_MAIL | MAPI_EXTENDED | MAPI_NEW_SESSION; if( FAILED(hResult = MAPILogonEx( 0, NULL, NULL, ulFlags, (LPMAPISESSION FAR *) &lpSession ))) { printf ( " FAILED with error: %X\r\n", hResult ); goto error; } else printf ( " OK\r\n" ); } printf ("3. Opening Address Book..."); { if( FAILED(hResult = lpSession-<OpenAddressBook( 0, NULL, 0, &lpAdrBook ))) { printf ( " FAILED with error: %X\r\n", hResult ); goto error; } else printf ( " OK\r\n" ); } printf ("4. Display AddressBook dialog box with one well..." ); { LPSTR rglpszDestTitles[1]; ULONG rgulDestComps[1]; ULONG ulFlags = 0; ULONG ulUIParam = 0; ulFlags = ulFlags | DIALOG_MODAL; rglpszDestTitles[0] = "To"; rgulDestComps[0] = MAPI_TO; ADRPARM adrparm; adrparm.cbABContEntryID = 0; adrparm.lpABContEntryID = NULL; adrparm.ulFlags = ulFlags; adrparm.lpReserved = NULL; adrparm.ulHelpContext = 0; adrparm.lpszHelpFileName = NULL; adrparm.lpfnABSDI = NULL; adrparm.lpfnDismiss = NULL; adrparm.lpvDismissContext = NULL; adrparm.lpszCaption = "MAPI ITP tests Address 1"; adrparm.lpszNewEntryTitle = "For this test dialog"; adrparm.lpszDestWellsTitle = "Selected Recipients:"; adrparm.cDestFields = 1; adrparm.nDestFieldFocus = 0; adrparm.lppszDestTitles = rglpszDestTitles; adrparm.lpulDestComps = rgulDestComps; adrparm.lpContRestriction = NULL; adrparm.lpHierRestriction = NULL; if( FAILED(hResult = lpAdrBook->Address( &ulUIParam, &adrparm, &lpadrlist ))) { printf ( " FAILED with error: %X\r\n", hResult ); goto error; } else printf ( " OK\r\n" ); } if (!lpadrlist) goto error; printf ( "5. Getting Entry IDs and opening each " ); printf ( "ADRENTRY...\r\n" ); { ULONG cEntry = 0; ULONG cProp = 0; for(cEntry=0; cEntry<lpadrlist->cEntries; cEntry++) { for(cProp=0; cProp < lpadrlist->aEntries[cEntry].cValues; cProp++) { printf ( " >Name: " ); if( lpadrlist->aEntries[cEntry].rgPropVals[cProp].ulPropTag == PR_DISPLAY_NAME ) { printf ( lpadrlist->aEntries[cEntry].rgPropVals[cProp].Value.LPSZ ); printf ( " ...\r\n" ); break; } } printf ( " -->Find EntryID " ); LPSPropValue lpsPropVal = NULL; lpsPropVal = PpropFindProp ( lpadrlist->aEntries[cEntry].rgPropVals, lpadrlist->aEntries[cEntry].cValues, PR_ENTRYID ); if (NULL == lpsPropVal) printf ( " FAILED\r\n " ); else printf ( " OK ... \r\n" ); printf ( " -->OpenEntry " ); { ULONG ulObjType = 0; LPMAPIPROP lpEntry = NULL; ULONG ulFlags = 0; ulFlags = ulFlags | MAPI_BEST_ACCESS; if( FAILED(hResult = lpAdrBook->OpenEntry(lpsPropVal->Value.bin.cb, (LPENTRYID)lpsPropVal->Value.bin.lpb, NULL, ulFlags, &ulObjType, (LPUNKNOWN*)&lpEntry))) printf ( " FAILED with error: %X\r\n", hResult ); else { printf ( " OK\r\n" ); lpEntry->Release(); } } if (lpsPropVal) MAPIFreeBuffer(lpsPropVal); } printf ( "6. Opening Default Message Store ... " ); { if (FAILED(hResult = OpenDefStore(lpSession, &lpMsgStore))) { printf ( " FAILED with error: %X\r\n", hResult ); goto error; } else printf ( " OK\r\n" ); } printf ( "7a. Get Receive Folder... " ); { SBinary sbInboxEID = {0, NULL}; ULONG ulObjType = 0; if (FAILED(hResult = lpMsgStore->GetReceiveFolder("IPM.Note", 0, &sbInboxEID.cb, (LPENTRYID *) &sbInboxEID.lpb, NULL))) { printf ( " FAILED with error: %X\r\n", hResult ); goto error; } else printf ( " OK\r\n" ); printf ( "7b. OpenEntry on Inbox[ASCII 133] " ); if (FAILED(hResult = lpSession->OpenEntry(sbInboxEID.cb, (LPENTRYID) sbInboxEID.lpb, NULL, MAPI_MODIFY, &ulObjType, (LPUNKNOWN *) &lpInbox))) printf ( " FAILED with error: %X\r\n", hResult); else printf ( " Open Inbox OK\r\n", hResult); if (sbInboxEID.cb) MAPIFreeBuffer(sbInboxEID.lpb); if (!lpInbox) goto error; } printf ( "8. Creating Message... " ); { LPMESSAGE lpMsg = NULL; if (FAILED(hResult = lpInbox->CreateMessage(NULL, 0, &lpMsg))) printf ( " FAILED with error: %X\r\n", hResult); else printf ( " OK\r\n" ); if (lpMsg) { printf ( "9. Modify Recipients... " ); if (FAILED(hResult = lpMsg->ModifyRecipients(MODRECIP_ADD, lpadrlist))) printf( " FAILED with error: %X\r\n", hResult); else { printf( " OK\r\n"); printf ( "10. Get Recipient table... " ); LPMAPITABLE lpRecips = NULL; if (FAILED(hResult = lpMsg->GetRecipientTable(0, &lpRecips))) printf ( " FAILED with error: %X\r\n", hResult); else { printf ( " OK\r\n" ); printf ( "11. GetRowCount... " ); LPSRowSet lpsRowSet = NULL; ULONG uRowCnt = 0; if (FAILED(hResult = lpRecips->GetRowCount(0, &uRowCnt))) printf (" FAILED with error: %X\r\n", hResult); else printf (" OK with Count: %u\r\n", uRowCnt ); printf ("13. Getting Entry IDs/OpenEntry...\r\n"); for (ULONG uRows=0; uRows < uRowCnt; uRows++) { printf ( " >QueryRows... " ); if (FAILED(hResult = lpRecips->QueryRows( (ULONG)1, 0, &lpsRowSet))) printf (" FAILED with error: %X\r\n", hResult); else { printf (" OK\r\n" ); LPSPropValue lpsPropVal1 = NULL; lpsPropVal1 = PpropFindProp ( lpsRowSet->aRow[0].lpProps, lpsRowSet->aRow[0].cValues, PR_DISPLAY_NAME ); if (NULL != lpsPropVal1) { printf( " -->Name: " ); printf( lpsPropVal1->Value.LPSZ ); printf( "\r\n" ); } printf ( " ----->Find EntryID..." ); LPSPropValue lpsPropVal = NULL; lpsPropVal = PpropFindProp ( lpsRowSet->aRow[0].lpProps, lpsRowSet->aRow[0].cValues, PR_ENTRYID ); if (NULL == lpsPropVal) printf ( " FAILED\r\n" ); else { printf ( " OK \r\n" ); ULONG ulObjType = 0; LPMAPIPROP lpEntry = NULL; ULONG ulFlags = 0; ulFlags = ulFlags | MAPI_BEST_ACCESS; printf ( " ----->OpenEntry..."); if ( FAILED(hResult = lpAdrBook->OpenEntry( lpsPropVal->Value.bin.cb, (LPENTRYID)lpsPropVal->Value.bin.lpb, NULL, ulFlags, &ulObjType, (LPUNKNOWN*)&lpEntry))) printf ( " FAILED with error: %X\r\n", hResult ); else { printf ( " OK\r\n" ); lpEntry->Release(); } MAPIFreeBuffer(lpsPropVal); } MAPIFreeBuffer(lpsRowSet); } } lpRecips->Release(); } } lpMsg->Release(); } } } error: if (lpInbox) lpInbox->Release(); if (lpMsgStore) { ULONG uflags = 0; lpMsgStore->StoreLogoff(&uflags); lpMsgStore->Release(); } if (lpadrlist) _FreeRowSet((LPSRowSet) lpadrlist); if (lpAdrBook) lpAdrBook->Release(); if (lpSession) { lpSession->Logoff(0,0,0); lpSession->Release(); } printf ( "***** END PROGRAM *****\r\n" ); return; } void _FreeRowSet( LPSRowSet lpRows ) { ULONG cRows; if ( !lpRows ) return; for( cRows = 0; cRows < lpRows->cRows; ++cRows ) { MAPIFreeBuffer( lpRows->aRow[cRows].lpProps ); } MAPIFreeBuffer( lpRows ); } HRESULT OpenDefStore(LPMAPISESSION m_pSess, LPMDB *m_pMDB) { LPMAPITABLE pStoresTbl = NULL; LPSRowSet pRow = NULL; SBinary sbEID = {0,NULL}; static SRestriction sres; SPropValue spv; HRESULT hRes; static SizedSPropTagArray(2,sptCols) = {2,PR_ENTRYID,PR_DEFAULT_STORE}; if (FAILED(hRes = m_pSess -> GetMsgStoresTable(0, &pStoresTbl))) { goto Quit; } sres.rt = RES_PROPERTY; sres.res.resProperty.relop = RELOP_EQ; sres.res.resProperty.ulPropTag = PR_DEFAULT_STORE; sres.res.resProperty.lpProp = &spv; spv.ulPropTag = PR_DEFAULT_STORE; spv.Value.b = TRUE; if (FAILED(hRes = HrQueryAllRows(pStoresTbl, (LPSPropTagArray) &sptCols, &sres, NULL, 0, &pRow))) goto Quit; if (pRow && pRow -> cRows && pRow -> aRow[0].cValues && PR_ENTRYID == pRow -> aRow[0].lpProps[0].ulPropTag) sbEID = pRow -> aRow[0].lpProps[0].Value.bin; else { hRes = MAPI_E_NOT_FOUND; goto Quit; } if (FAILED(hRes = m_pSess -> OpenMsgStore(0, sbEID.cb, (LPENTRYID)sbEID.lpb, NULL, MDB_WRITE, m_pMDB))) goto Quit; Quit: FreeProws(pRow); if (pStoresTbl) pStoresTbl -> Release(); return hRes; }
REFERENCES
Excerpts of code were used from the following samples:
- Abview.cli available from the Microsoft FTP site
- "HelloMAPI" (from the Companion CD of the book Inside MAPI)
Keywords: kbbug kbnofix kbmsg kbcode KB174394