Click here to Skip to main content
11,412,182 members (59,594 online)
Click here to Skip to main content

Importing contacts from Outlook

, 20 Feb 2003
Rate this:
Please Sign up or sign in to vote.
Exmaple source code to import items from Outlook using the Office/Outlook Object Model.

Sample Image - maximum width is 600 pixels


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 Wink | ;-) ) C++ programmer do for this? Since 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",    "_DRecipientControl");
//For Office 2000 
#import "E:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll" named_guids
#import "E:\Microsoft Office\Office10\MSOUTL.OLB" \ no_namespace
    exclude("_IRecipientControl", "_DRecipientControl");
//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());

This sample imports contact 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 a Calendar folder one just needs to make an object of _AppointmentItemPtr smart pointer class instead of _ContactItemPtr.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Deepesh Dhapola
Web Developer
India India

Comments and Discussions PinmemberMember 984981522-Feb-13 1:50 
QuestionAny Chance of getting the source in C# or Pinmember99pshop24-Jan-11 11:41 
QuestionNeed to Import e-mail attachments to C# program PinmemberKasunmit15-May-10 18:29 
GeneralCheck the alias Pinmemberfbi56fbi6-Sep-09 23:14 
QuestionProblem with Outlook 2007 Pinmemberraulhmacias15-Apr-09 15:40 
QuestionRe: Problem with Outlook 2007 Pinmemberandkeller15-Jun-09 21:52 
AnswerRe: Problem with Outlook 2007 Pinmemberrbrunton27-Jul-09 2:14 
AnswerRe: Problem with Outlook 2007 Pinmemberhufubin13-Nov-09 21:01 
AnswerRe: Problem with Outlook 2007 PinmemberMember 383426513-Oct-10 1:49 
Generalgetting mails from msoutlook Pinmemberalexenoy16-Mar-06 1:48 
QuestionHow do I do all this using C# PinmemberNewbieDude15-Mar-06 22:05 
QuestionHow can I get images from e-mail message? PinmemberZahid Younas6-Jan-06 20:38 
QuestionHow can I get web-page property using MAPI Pinmembertoddor_sturt28-Dec-05 16:42 
GeneralAccessing other user's Outlook folders PinmemberKokas1-Nov-05 3:19 
QuestionHOW TO don't show waring Dialog? Pinmemberwangsongshan11-Sep-05 20:30 
AnswerRe: HOW TO don't show waring Dialog? PinmemberDeepesh Dhapola11-Sep-05 20:36 
GeneralRe: HOW TO don't show waring Dialog? Pinmembergoebish26-Apr-06 23:24 
GeneralRe: HOW TO don't show waring Dialog? Pinmembercanido15-Jun-07 0:24 
Answer-- HERE IS HOW TO GET AROUND THE WARNING -- PinmemberMember 60417929-Jul-08 13:43 
QuestionRe: HOW TO don't show waring Dialog? Pinmemberlicj200822-Jul-07 0:31 
GeneralImporting messages PinmemberSloanCode15-Aug-05 1:31 
GeneralOutLook2003 security problem Pinmembernkzz6-Apr-05 21:56 
GeneralUnable to instantiate Outlook Pinmemberriki_risnandar19-Mar-05 18:19 
GeneralRe: Unable to instantiate Outlook Pinmemberbharadwajgangadhar5-Oct-05 5:25 
GeneralRe: Unable to instantiate Outlook PinmemberZahid Younas6-Jan-06 1:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.5 | Last Updated 21 Feb 2003
Article Copyright 2003 by Deepesh Dhapola
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid