Importing contacts from Outlook


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: VC6, Outlook 2000/XP.

Outlook has become a de facto standard in Personal Information Management software. Almost everyone uses this software for managing their needs. There arises the need for programmatically manipulating information stored in Outlook. Microsoft has provided the Outlook Object Model for this very same purpose. A closer look at the samples on MSDN reveals that almost all samples are in Visual Basic. What should the (not so poor ;-)) C++ programmer do about this? Because the Outlook Object Model is a collection of COM interfaces, any COM-compliant language can useit. This sample can import contacts from any contacts folder in Outlook.

To use Office/Outlook Objects in C++, following files needs to be imported...

For Office XP:

#import "E:\Program Files\Common Files\Microsoft Shared\Office10\
            mso.dll" named_guids
#import "E:\Microsoft Office\Office10\MSOUTL.OLB" \
            no_namespace exclude("_IRecipientControl",

For Office 2000:

#import "I:\My Programs\Office2K\Office\mso9.dll" named_guids

#import "I:\My Programs\Office2K\Office\MSOUTL9.OLB" \
            no_namespace exclude("_IRecipientControl",

This sample imports Contacts information but a slight modification will enable this to import any other information from Outlook as well. This includes Appointment Items, Email Messages, Notes, Tasks, and more.

For example, to import Appointment Items from the Calendar folder, one just needs to make an object of the _AppointmentItemPtr smart pointer class instead of _ContactItemPtr.

Code to import Contacts...

_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;



  if (FAILED(hr))
    MessageBox("Unable to instantiate Outlook.",
               "Outlook Error",MB_OK);

  if (m_Option.GetCheck()) //default outlook contacts folder
    if (pFolder==NULL)
      MessageBox("Could not find default contacts folder.",
                 "Outlook Error");
  else    //display folder selection window
    if (pFolder==NULL)

    if (pFolder->GetDefaultItemType()!=olContactItem)
      MessageBox("Select folder is not a Contact folder.",
                 "Outlook Contacts");

  if (pItems==NULL)
    MessageBox("Unabel to get Contact Items.",
               "Outlook Error");



    if (pContact==NULL)
    CString strTemp;
    strTemp=(char *)pContact->GetFullName();
    strTemp=strTemp + "<";
    strTemp=strTemp + (char *)pContact->GetEmail1Address();
    strTemp=strTemp + ">";


catch(_com_error &e)
  MessageBox((char *)e.Description());


Download demo project - 6.49 Kb
Download source - 375 Kb


  • Get rid of the message box when running the program

    Posted by itaihor on 10/11/2005 09:34am

    When running the program, the next message box appears: "A program is trying to access e-mail addresses...." How can I get rid of this message?

  • writing the same app for a console

    Posted by Andy Sponik on 04/22/2004 12:39pm

    Hi, I'm trying to write the same app but for a console application. I'm not really familiar with c++ so I'm not sure what to do. Could someone tell me which changes I have to make to make this work (I'm trying to do this so later on I can export the contacts to a java app). thx, Andy

  • Retrieving Calendar Info

    Posted by Legacy on 09/11/2003 07:00am

    Originally posted by: Chris Bartle

    I had been looking for a way to extract calendar data from Outlook 2000 and this code works well for that too. Just replace _ContactItemPtr with _AppointmentItemPtr and use GetDefaultFolder(olFolderCalendar). I've been having a hard time finding any good documentation from Microsoft on using these classes in VC, so I've been stuck decoding the header files. Still, this code provides a great launching point for accessing more than just Outlook contacts.

  • How to import and export vcard files from Outlook in vc application?

    Posted by Legacy on 08/12/2003 07:00am

    Originally posted by: Dennis liao

    Dear all:
    Do anybody knows How to import and export vcard files from Outlook in vc application?
    Hoping for a reply,
    Thanks and Regards,
    Dennis liao

  • Creating Email Account..

    Posted by Legacy on 03/03/2003 08:00am

    Originally posted by: Paras Shah

    Hi there,

    Is there any possibility to create/modify the email account in Outlook 2002(office xp) programmatically using vc++?

    Paras Shah

  • Doesn't return email address

    Posted by Legacy on 02/10/2003 08:00am

    Originally posted by: majk


    it's elegant concept. The problem I have:
    'GetEmail1Address' returns just string like here: '/o=XYZ/ou=ABC012/cn=Recipients/cn=Firstname Lastname'
    'GetEmail2Address' and 'GetEmail3Address' return empty string.
    Any idea?


  • Dynamic Import files

    Posted by Legacy on 12/25/2002 08:00am

    Originally posted by: kc

    How to dynamic import mso9.dll and MSOUTL9.OLB in my program? I got the file path from the Registry but I couldn't do it dynamically in my program.

    #import "C:\\Program Files\\Microsoft Office\\Office\\mso9.dll" named_guids

    #import "C:\\Program Files\\Microsoft Office\\Office\\MSOUTL9.OLB" \
    no_namespace exclude("_IRecipientControl", "_DRecipientControl")

  • how to make "Select folder" open in a center?

    Posted by Legacy on 09/25/2002 07:00am

    Originally posted by: dima

    namespace::PickFolder() method displays outlook's "Select Folder" window in a corner. Does anyone know how to force the window to be opened in a center?

  • What namespaces exist

    Posted by Legacy on 08/29/2002 07:00am

    Originally posted by: Peter Nelson

    Is there a way to enumerate the namespaces that can be retrieved? You get the 'MAPI' namespace each time - but that returns no contacts to me - even though when I open up Outlook I've got dozens. I'm assuming that my user is not set up as an exchange user, and so has no Mapi entries... but there must still be a way.


  • Great Code

    Posted by Legacy on 07/30/2002 07:00am

    Originally posted by: Robert

    Thank you very much. This code is exactly what I've been looking for. There is not enough sample code for Outlook out there.

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date