Microsoft KB Archive/174394: Difference between revisions

From BetaArchive Wiki
(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 &lt;mapiutil.h&gt;
<pre class="codesample">  #include <mapiutil.h>
   #include &lt;stdio.h&gt;
   #include <stdio.h>


   void _FreeRowSet( LPSRowSet );
   void _FreeRowSet( LPSRowSet );
Line 92: Line 92:
   void main ( void )
   void main ( void )
   {
   {
     printf ( &quot;**** Begin program ****\r\n&quot; );
     printf ( "**** Begin program ****\r\n" );


     HRESULT      hResult    = 0;
     HRESULT      hResult    = 0;
Line 101: Line 101:
     LPADRLIST    lpadrlist  = NULL;
     LPADRLIST    lpadrlist  = NULL;


     printf ( &quot;1. Initializing MAPI...&quot; );
     printf ( "1. Initializing MAPI..." );
     {
     {
       if ( FAILED(hResult = MAPIInitialize( NULL )))
       if ( FAILED(hResult = MAPIInitialize( NULL )))
       {
       {
           printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
           printf ( " FAILED with error: %X\r\n", hResult );
           goto error;
           goto error;
       }
       }
       else
       else
           printf ( &quot; OK\r\n&quot; );
           printf ( " OK\r\n" );
     }
     }


     printf ( &quot;2. Logging on...&quot;);
     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 *) &amp;lpSession )))
                       (LPMAPISESSION FAR *) &lpSession )))
       {
       {
         printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
         printf ( " FAILED with error: %X\r\n", hResult );
         goto error;
         goto error;
       }
       }
       else
       else
         printf ( &quot; OK\r\n&quot; );
         printf ( " OK\r\n" );
     }
     }


     printf (&quot;3. Opening Address Book...&quot;);
     printf ("3. Opening Address Book...");
     {
     {
       if( FAILED(hResult = lpSession-&lt;OpenAddressBook( 0,
       if( FAILED(hResult = lpSession-<OpenAddressBook( 0,
                                   NULL, 0, &amp;lpAdrBook )))
                                   NULL, 0, &lpAdrBook )))
       {
       {
         printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
         printf ( " FAILED with error: %X\r\n", hResult );
         goto error;
         goto error;
       }
       }
       else
       else
         printf ( &quot; OK\r\n&quot; );
         printf ( " OK\r\n" );
     }
     }


     printf (&quot;4. Display AddressBook dialog box with one well...&quot; );
     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]        = &quot;To&quot;;
       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        = &quot;MAPI ITP tests Address 1&quot;;
       adrparm.lpszCaption        = "MAPI ITP tests Address 1";
       adrparm.lpszNewEntryTitle  = &quot;For this test dialog&quot;;
       adrparm.lpszNewEntryTitle  = "For this test dialog";
       adrparm.lpszDestWellsTitle = &quot;Selected Recipients:&quot;;
       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-&gt;Address( &amp;ulUIParam,
       if( FAILED(hResult = lpAdrBook->Address( &ulUIParam,
                                       &amp;adrparm, &amp;lpadrlist )))
                                       &adrparm, &lpadrlist )))
       {
       {
         printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
         printf ( " FAILED with error: %X\r\n", hResult );
         goto error;
         goto error;
       }
       }
       else
       else
         printf ( &quot; OK\r\n&quot; );
         printf ( " OK\r\n" );
     }
     }


Line 187: Line 187:
       goto error;
       goto error;


     printf ( &quot;5. Getting Entry IDs and opening each &quot; );
     printf ( "5. Getting Entry IDs and opening each " );
     printf ( &quot;ADRENTRY...\r\n&quot; );
     printf ( "ADRENTRY...\r\n" );
     {
     {
       ULONG  cEntry  = 0;
       ULONG  cEntry  = 0;
       ULONG  cProp  = 0;
       ULONG  cProp  = 0;


       for(cEntry=0; cEntry&lt;lpadrlist-&gt;cEntries; cEntry++)
       for(cEntry=0; cEntry<lpadrlist->cEntries; cEntry++)
       {
       {
         for(cProp=0;
         for(cProp=0;
             cProp &lt; lpadrlist-&gt;aEntries[cEntry].cValues;
             cProp < lpadrlist->aEntries[cEntry].cValues;
             cProp++)
             cProp++)
         {
         {
           printf ( &quot;   &gt;Name: &quot; );
           printf ( "   >Name: " );
           if( lpadrlist-&gt;aEntries[cEntry].rgPropVals[cProp].ulPropTag
           if( lpadrlist->aEntries[cEntry].rgPropVals[cProp].ulPropTag
               == PR_DISPLAY_NAME )
               == PR_DISPLAY_NAME )
           {
           {
             printf (
             printf (
               lpadrlist-&gt;aEntries[cEntry].rgPropVals[cProp].Value.LPSZ
               lpadrlist->aEntries[cEntry].rgPropVals[cProp].Value.LPSZ
                     );
                     );
             printf ( &quot; ...\r\n&quot; );
             printf ( " ...\r\n" );
             break;
             break;
           }
           }
         }
         }


         printf ( &quot;   --&gt;Find EntryID &quot; );
         printf ( "   -->Find EntryID " );


         LPSPropValue lpsPropVal = NULL;
         LPSPropValue lpsPropVal = NULL;
         lpsPropVal = PpropFindProp (
         lpsPropVal = PpropFindProp (
                           lpadrlist-&gt;aEntries[cEntry].rgPropVals,
                           lpadrlist->aEntries[cEntry].rgPropVals,
                           lpadrlist-&gt;aEntries[cEntry].cValues,
                           lpadrlist->aEntries[cEntry].cValues,
                           PR_ENTRYID );
                           PR_ENTRYID );


         if (NULL == lpsPropVal)
         if (NULL == lpsPropVal)
           printf ( &quot; FAILED\r\n &quot; );
           printf ( " FAILED\r\n " );
         else
         else
           printf ( &quot; OK ... \r\n&quot; );
           printf ( " OK ... \r\n" );


         printf ( &quot;   --&gt;OpenEntry &quot; );
         printf ( "   -->OpenEntry " );
         {
         {
           ULONG      ulObjType      = 0;
           ULONG      ulObjType      = 0;
Line 232: Line 232:


           if( FAILED(hResult =
           if( FAILED(hResult =
               lpAdrBook-&gt;OpenEntry(lpsPropVal-&gt;Value.bin.cb,
               lpAdrBook->OpenEntry(lpsPropVal->Value.bin.cb,
                         (LPENTRYID)lpsPropVal-&gt;Value.bin.lpb,
                         (LPENTRYID)lpsPropVal->Value.bin.lpb,
                         NULL, ulFlags, &amp;ulObjType,
                         NULL, ulFlags, &ulObjType,
                         (LPUNKNOWN*)&amp;lpEntry)))
                         (LPUNKNOWN*)&lpEntry)))
             printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
             printf ( " FAILED with error: %X\r\n", hResult );
           else
           else
           {
           {
             printf ( &quot; OK\r\n&quot; );
             printf ( " OK\r\n" );
             lpEntry-&gt;Release();
             lpEntry->Release();
           }
           }
           }
           }
Line 248: Line 248:
       }
       }


       printf ( &quot;6. Opening Default Message Store ... &quot; );
       printf ( "6. Opening Default Message Store ... " );
       {
       {
         if (FAILED(hResult = OpenDefStore(lpSession, &amp;lpMsgStore)))
         if (FAILED(hResult = OpenDefStore(lpSession, &lpMsgStore)))
         {
         {
           printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
           printf ( " FAILED with error: %X\r\n", hResult );
           goto error;
           goto error;
         }
         }
         else
         else
           printf ( &quot; OK\r\n&quot; );
           printf ( " OK\r\n" );
       }
       }


         printf ( &quot;7a. Get Receive Folder... &quot; );
         printf ( "7a. Get Receive Folder... " );
         {
         {
         SBinary sbInboxEID = {0, NULL};
         SBinary sbInboxEID = {0, NULL};
Line 265: Line 265:


         if (FAILED(hResult =
         if (FAILED(hResult =
             lpMsgStore-&gt;GetReceiveFolder(&quot;IPM.Note&quot;, 0,
             lpMsgStore->GetReceiveFolder("IPM.Note", 0,
                         &amp;sbInboxEID.cb,
                         &sbInboxEID.cb,
                         (LPENTRYID *) &amp;sbInboxEID.lpb, NULL)))
                         (LPENTRYID *) &sbInboxEID.lpb, NULL)))
         {
         {
           printf ( &quot; FAILED with error: %X\r\n&quot;, hResult );
           printf ( " FAILED with error: %X\r\n", hResult );
           goto error;
           goto error;
         }
         }
         else
         else
           printf ( &quot; OK\r\n&quot; );
           printf ( " OK\r\n" );


         printf ( &quot;7b. OpenEntry on Inbox[ASCII 133] &quot; );
         printf ( "7b. OpenEntry on Inbox[ASCII 133] " );
         if (FAILED(hResult =
         if (FAILED(hResult =
             lpSession-&gt;OpenEntry(sbInboxEID.cb,
             lpSession->OpenEntry(sbInboxEID.cb,
                         (LPENTRYID) sbInboxEID.lpb, NULL,
                         (LPENTRYID) sbInboxEID.lpb, NULL,
                         MAPI_MODIFY, &amp;ulObjType,
                         MAPI_MODIFY, &ulObjType,
                         (LPUNKNOWN *) &amp;lpInbox)))
                         (LPUNKNOWN *) &lpInbox)))
           printf ( &quot; FAILED with error: %X\r\n&quot;, hResult);
           printf ( " FAILED with error: %X\r\n", hResult);
         else
         else
           printf ( &quot;   Open Inbox OK\r\n&quot;, hResult);
           printf ( "   Open Inbox OK\r\n", hResult);


         if (sbInboxEID.cb)
         if (sbInboxEID.cb)
Line 292: Line 292:
       }
       }


       printf ( &quot;8. Creating Message... &quot; );
       printf ( "8. Creating Message... " );
       {
       {
         LPMESSAGE lpMsg = NULL;
         LPMESSAGE lpMsg = NULL;


         if (FAILED(hResult =
         if (FAILED(hResult =
             lpInbox-&gt;CreateMessage(NULL, 0, &amp;lpMsg)))
             lpInbox->CreateMessage(NULL, 0, &lpMsg)))
           printf ( &quot; FAILED with error: %X\r\n&quot;, hResult);
           printf ( " FAILED with error: %X\r\n", hResult);
         else
         else
             printf ( &quot; OK\r\n&quot; );
             printf ( " OK\r\n" );


           if (lpMsg)
           if (lpMsg)
           {
           {
             printf ( &quot;9. Modify Recipients... &quot; );
             printf ( "9. Modify Recipients... " );
             if (FAILED(hResult =
             if (FAILED(hResult =
                 lpMsg-&gt;ModifyRecipients(MODRECIP_ADD, lpadrlist)))
                 lpMsg->ModifyRecipients(MODRECIP_ADD, lpadrlist)))
               printf( &quot; FAILED with error: %X\r\n&quot;, hResult);
               printf( " FAILED with error: %X\r\n", hResult);
             else
             else
             {
             {
               printf( &quot; OK\r\n&quot;);
               printf( " OK\r\n");


               printf ( &quot;10. Get Recipient table... &quot; );
               printf ( "10. Get Recipient table... " );
               LPMAPITABLE lpRecips = NULL;
               LPMAPITABLE lpRecips = NULL;
               if (FAILED(hResult =
               if (FAILED(hResult =
                   lpMsg-&gt;GetRecipientTable(0, &amp;lpRecips)))
                   lpMsg->GetRecipientTable(0, &lpRecips)))
                 printf ( &quot; FAILED with error: %X\r\n&quot;, hResult);
                 printf ( " FAILED with error: %X\r\n", hResult);
               else
               else
               {
               {
                 printf ( &quot; OK\r\n&quot; );
                 printf ( " OK\r\n" );


                 printf ( &quot;11. GetRowCount... &quot; );
                 printf ( "11. GetRowCount... " );
                 LPSRowSet lpsRowSet = NULL;
                 LPSRowSet lpsRowSet = NULL;
                 ULONG    uRowCnt  = 0;
                 ULONG    uRowCnt  = 0;


                 if (FAILED(hResult =
                 if (FAILED(hResult =
                     lpRecips-&gt;GetRowCount(0, &amp;uRowCnt)))
                     lpRecips->GetRowCount(0, &uRowCnt)))
                   printf (&quot; FAILED with error: %X\r\n&quot;, hResult);
                   printf (" FAILED with error: %X\r\n", hResult);
                 else
                 else
                   printf (&quot; OK with Count: %u\r\n&quot;, uRowCnt );
                   printf (" OK with Count: %u\r\n", uRowCnt );


                 printf (&quot;13. Getting Entry IDs/OpenEntry...\r\n&quot;);
                 printf ("13. Getting Entry IDs/OpenEntry...\r\n");
                 for (ULONG uRows=0; uRows &lt; uRowCnt; uRows++)
                 for (ULONG uRows=0; uRows < uRowCnt; uRows++)
                 {
                 {
                   printf ( &quot;   &gt;QueryRows... &quot; );
                   printf ( "   >QueryRows... " );
                   if (FAILED(hResult =
                   if (FAILED(hResult =
                     lpRecips-&gt;QueryRows( (ULONG)1, 0, &amp;lpsRowSet)))
                     lpRecips->QueryRows( (ULONG)1, 0, &lpsRowSet)))
                   printf (&quot; FAILED with error: %X\r\n&quot;, hResult);
                   printf (" FAILED with error: %X\r\n", hResult);
                 else
                 else
                 {
                 {
                   printf (&quot; OK\r\n&quot; );
                   printf (" OK\r\n" );


                   LPSPropValue lpsPropVal1 = NULL;
                   LPSPropValue lpsPropVal1 = NULL;
                   lpsPropVal1 = PpropFindProp (
                   lpsPropVal1 = PpropFindProp (
                                   lpsRowSet-&gt;aRow[0].lpProps,
                                   lpsRowSet->aRow[0].lpProps,
                                   lpsRowSet-&gt;aRow[0].cValues,
                                   lpsRowSet->aRow[0].cValues,
                                   PR_DISPLAY_NAME );
                                   PR_DISPLAY_NAME );
                   if (NULL != lpsPropVal1)
                   if (NULL != lpsPropVal1)
                   {
                   {
                     printf( &quot;   --&gt;Name: &quot; );
                     printf( "   -->Name: " );
                     printf( lpsPropVal1-&gt;Value.LPSZ );
                     printf( lpsPropVal1->Value.LPSZ );
                     printf( &quot;\r\n&quot; );
                     printf( "\r\n" );
                   }
                   }


                   printf ( &quot;   -----&gt;Find EntryID...&quot; );
                   printf ( "   ----->Find EntryID..." );
                   LPSPropValue lpsPropVal = NULL;
                   LPSPropValue lpsPropVal = NULL;
                   lpsPropVal = PpropFindProp (
                   lpsPropVal = PpropFindProp (
                                   lpsRowSet-&gt;aRow[0].lpProps,
                                   lpsRowSet->aRow[0].lpProps,
                                   lpsRowSet-&gt;aRow[0].cValues,
                                   lpsRowSet->aRow[0].cValues,
                                   PR_ENTRYID );
                                   PR_ENTRYID );


                   if (NULL == lpsPropVal)
                   if (NULL == lpsPropVal)
                       printf ( &quot; FAILED\r\n&quot; );
                       printf ( " FAILED\r\n" );
                     else
                     else
                     {
                     {
                       printf ( &quot; OK \r\n&quot; );
                       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 ( &quot;   -----&gt;OpenEntry...&quot;);
                       printf ( "   ----->OpenEntry...");
                       if ( FAILED(hResult =
                       if ( FAILED(hResult =
                           lpAdrBook-&gt;OpenEntry(
                           lpAdrBook->OpenEntry(
                                 lpsPropVal-&gt;Value.bin.cb,
                                 lpsPropVal->Value.bin.cb,
                                 (LPENTRYID)lpsPropVal-&gt;Value.bin.lpb,
                                 (LPENTRYID)lpsPropVal->Value.bin.lpb,
                                 NULL, ulFlags, &amp;ulObjType,
                                 NULL, ulFlags, &ulObjType,
                                 (LPUNKNOWN*)&amp;lpEntry)))
                                 (LPUNKNOWN*)&lpEntry)))
                         printf ( &quot; FAILED with error: %X\r\n&quot;,
                         printf ( " FAILED with error: %X\r\n",
                                 hResult );
                                 hResult );
                       else
                       else
                       {
                       {
                         printf ( &quot; OK\r\n&quot; );
                         printf ( " OK\r\n" );
                         lpEntry-&gt;Release();
                         lpEntry->Release();
                       }
                       }


Line 394: Line 394:
                 }
                 }


                 lpRecips-&gt;Release();
                 lpRecips->Release();
               }
               }


             }
             }
             lpMsg-&gt;Release();
             lpMsg->Release();
           }
           }


Line 407: Line 407:
       error:
       error:
         if (lpInbox)
         if (lpInbox)
           lpInbox-&gt;Release();
           lpInbox->Release();


         if (lpMsgStore)
         if (lpMsgStore)
         {
         {
           ULONG uflags = 0;
           ULONG uflags = 0;
           lpMsgStore-&gt;StoreLogoff(&amp;uflags);
           lpMsgStore->StoreLogoff(&uflags);
           lpMsgStore-&gt;Release();
           lpMsgStore->Release();
         }
         }


Line 420: Line 420:


         if (lpAdrBook)
         if (lpAdrBook)
           lpAdrBook-&gt;Release();
           lpAdrBook->Release();


         if (lpSession)
         if (lpSession)
         {
         {
           lpSession-&gt;Logoff(0,0,0);
           lpSession->Logoff(0,0,0);
           lpSession-&gt;Release();
           lpSession->Release();
         }
         }
         printf ( &quot;***** END PROGRAM *****\r\n&quot; );
         printf ( "***** END PROGRAM *****\r\n" );


       return;
       return;
Line 439: Line 439:
         return;
         return;


       for( cRows = 0; cRows &lt; lpRows-&gt;cRows; ++cRows )
       for( cRows = 0; cRows < lpRows->cRows; ++cRows )
       {
       {
         MAPIFreeBuffer( lpRows-&gt;aRow[cRows].lpProps );
         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 -&gt; GetMsgStoresTable(0, &amp;pStoresTbl)))
       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 = &amp;spv;
       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) &amp;sptCols,
                               (LPSPropTagArray) &sptCols,
                               &amp;sres, NULL, 0, &amp;pRow)))
                               &sres, NULL, 0, &pRow)))
         goto Quit;
         goto Quit;


       if (pRow                    &amp;&amp;
       if (pRow                    &&
           pRow -&gt; cRows          &amp;&amp;
           pRow -> cRows          &&
           pRow -&gt; aRow[0].cValues &amp;&amp;
           pRow -> aRow[0].cValues &&
           PR_ENTRYID == pRow -&gt; aRow[0].lpProps[0].ulPropTag)
           PR_ENTRYID == pRow -> aRow[0].lpProps[0].ulPropTag)
         sbEID  = pRow -&gt; aRow[0].lpProps[0].Value.bin;
         sbEID  = pRow -> aRow[0].lpProps[0].Value.bin;


       else
       else
Line 490: Line 490:


       if (FAILED(hRes =
       if (FAILED(hRes =
           m_pSess -&gt; OpenMsgStore(0, sbEID.cb,
           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 -&gt; Release();
           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]
* &quot;HelloMAPI&quot; (from the Companion CD of the book ''Inside MAPI'')
* "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

  1. Create a Console Application containing a program with code shown in step 3.
  2. Add Mapi32.lib to the Object/Library modules text box in the Link tab of the Project Settings dialog box.
  3. 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