Microsoft KB Archive/259298

= How to use an Outlook Object Model from Visual C++ by using a #import statement =

Article ID: 259298

Article Last Modified on 9/9/2005

-

APPLIES TO


 * Microsoft Office Outlook 2003
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q259298



SUMMARY
This article describes how to use Microsoft Outlook Object Model from Visual C++ through the #import statement and smart pointers.



MORE INFORMATION
The #import statement is different for each version of the Microsoft Outlook Object Library (Msoutlxx.olb).

The following code is an example of an #import statement that works with all versions of the Microsoft Outlook Object Model: // Define this according to the Outlook Object // Model version you are compiling under //#define OUTL10   // Outlook 2002 //#define OUTL9    // Outlook 2000
 * 1) define OUTL11 // Outlook 2003


 * 1) pragma warning(disable:4146)

#import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE11\mso.dll&quot; \ no_namespace #import &quot;C:\Program Files\Microsoft Office\OFFICE11\msoutl.olb&quot; \ rename_namespace(&quot;Outlook&quot;) #import &quot;C:\Program Files\Common Files\Microsoft Shared\OFFICE10\mso.dll&quot; \ no_namespace, rename(&quot;DocumentProperties&quot;, &quot;DocProps&quot;) #import &quot;C:\Program Files\Microsoft Office\OFFICE10\msoutl.olb&quot; \ rename_namespace(&quot;Outlook&quot;) #import &quot;C:\Program Files\Microsoft Office\Office\mso9.dll&quot; \ no_namespace, rename(&quot;DocumentProperties&quot;, &quot;DocProps&quot;) #import &quot;C:\Program Files\Microsoft Office\Office\msoutl9.olb&quot; \ rename_namespace(&quot;Outlook&quot;)
 * 1) if defined(OUTL11) // Outlook 2003
 * 1) elif defined(OUTL10) // Outlook 2002
 * 1) elif defined(OUTL9) // Outlook 2000
 * 1) endif // OUTL11


 * 1) pragma warning(default:4146)

using namespace Outlook; Note You must change the paths for the system, and then build your application by using the earliest version of Microsoft Outlook to avoid backward compatibility issues.

The following code is an example of how to log on to your default profile, and then print the number of messages in the Inbox folder. The following code also demonstrates how you can use the #import statements from the previous code by using smart pointers. _ApplicationPtr spApp(&quot;Outlook.Application&quot;); _NameSpacePtr pMAPI = spApp->GetNamespace(&quot;MAPI&quot;);

pMAPI->Logon(&quot;&quot;,&quot;&quot;,false,false);

MAPIFolderPtr InboxFolder = pMAPI->GetDefaultFolder(olFolderInbox); _ItemsPtr Items = InboxFolder->GetItems; printf(&quot;Total number of messages in Inbox - %d \n&quot;, Items->Count); After you compile the project, four files are created for you by the #import statement: MsoXX.tli, MsoXX.tlh, MsoutlXX.tli, and MsoutlXX.tlh. If you manually add these files to your project, you can view all the Office and Outlook library interfaces in the ClassView class, and the IntelliSense option displays the parameters as you type the interface methods.

Keywords: kbhowto kboutlookobj kbmsg KB259298

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.