How To Resolve Ambiguous Names with the Outlook Object Model Using Visual C++ (260626)



The information in this article applies to:

  • Microsoft Outlook 2000
  • Microsoft Outlook 98
  • Microsoft Visual C++, 32-bit Editions 6.0

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 "References" 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("Outlook.Application.9");
   _NameSpacePtr objNameSpace = objOutlook->GetNamespace("MAPI");
   MyRecipient = objNameSpace->CreateRecipient(_bstr_t("Recipient Name"));
   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("Recipient@EmailAddress")) {
                  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;
   }
}
				

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

259298 How To Use Microsoft Outlook Object Model From Visual C++ Through an #IMPORT Statement


Modification Type:MinorLast Reviewed:7/2/2004
Keywords:kbhowto kbMsg kbOutlookObj KB260626