Microsoft KB Archive/260626

= How To Resolve Ambiguous Names with the Outlook Object Model Using Visual C++ =

Article ID: 260626

Article Last Modified on 7/2/2004

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Outlook 98 Standard Edition
 * Microsoft Visual C++ 6.0 Service Pack 5

-



This article was previously published under Q260626



SUMMARY
This article demonstrates how to programmatically handle duplicate names that cause ambiguous name resolution when you use the Outlook Object Model (OOM).

For more information on using smart pointers, see the &quot;References&quot; section.



MORE INFORMATION
To resolve duplicate names programmatically, you must have another method of identifying each recipient (other than the recipient's name).

The following sample subroutine uses each recipient's e-mail address to confirm the selection of the duplicate recipients. You can also use any other information that you have for each recipient if the data corresponds with the properties that are provided in the OOM. void AmbiguousNameRes {  RecipientPtr MyRecipient; AddressListsPtr spAdrLsts; AddressListPtr spAdrLst; AddressEntriesPtr spAdrEnts; AddressEntryPtr spAdrEnt;

// Ambiguous name resolution technique. _ApplicationPtr objOutlook(&quot;Outlook.Application.9&quot;); _NameSpacePtr objNameSpace = objOutlook->GetNamespace(&quot;MAPI&quot;); MyRecipient = objNameSpace->CreateRecipient(_bstr_t(&quot;Recipient Name&quot;)); MyRecipient->Resolve; if (MyRecipient->Resolved == FALSE) { // failed due to 0 or >1 matches spAdrLsts = objNameSpace->GetAddressLists; for (long i = 1; i < spAdrLsts->GetCount; i++) { spAdrLst = spAdrLsts->Item(i); spAdrEnts = spAdrLst->GetAddressEntries; for (long j = 1; j < spAdrEnts->GetCount; j++) { spAdrEnt = spAdrEnts->Item(j); if (spAdrEnt->GetName == MyRecipient->GetName) { // Determine if correct name. if (spAdrEnt->GetAddress ==                   _bstr_t(&quot;Recipient@EmailAddress&quot;)) { MyRecipient->AddressEntry = spAdrEnt; MyRecipient->Resolve; if (MyRecipient->Resolved == TRUE) { // Have valid recipient object. }                 else { // Try other properties? }              }            }            spAdrEnt = NULL; }        spAdrEnts = NULL; spAdrLst = NULL; }     spAdrLsts = NULL; objNameSpace = NULL; objOutlook = NULL; } }

