Home arrow C++ arrow Page 2 - Building An Outlook COM Add-In With VC /ATL

Building An Outlook COM Add-In With VC /ATL

One of the great things about Windows is the ability that we have to create COM-based add-in's for the entire suit of Office 2000 applications. In this article, Amit shows us how to create an Outlook 2000 COM add-in using a pure Visual C ATL COM object. He starts by writing a basic functional COM add-in, and then adds standard user interface elements such as toolbars and menu items to Outlook. He finishes up by showing us how to respond to their events.

Author Info:
By: Amit Dey
Rating: 5 stars5 stars5 stars5 stars5 stars / 65
February 17, 2002
  1. · Building An Outlook COM Add-In With VC /ATL
  2. · Getting started
  3. · Building a minimal COM add-in
  4. · Command and conquer
  5. · Command and conquer (contd.)
  6. · Lord of the (disp) sinks
  7. · Conclusion

print this article

Building An Outlook COM Add-In With VC /ATL - Getting started
(Page 2 of 7 )

An Office add-in is a COM Automation component that dynamically extends/enhances and controls any Office suite of applications. Microsoft Office 2000 and later versions support a new, uniform design architecture for building such application add-ins. Typically such add-ins are housed in ActiveX DLL's (in-process servers) and can be dynamically loaded and unloaded by the user through the main application.

An Office COM add-in must implement the _IDTExtensibility2 interface. The IDTExtensibility2 interface is defined in the MSADDin designer type library (MSADDNDR.dll/MSADDNDR.tlb) file, which usually exists in the c:\Program Files\Common Files\Designer folder.

The interface definition looks like this:

enum {

ext_cm_AfterStartup = 0,

ext_cm_Startup = 1,

ext_cm_External = 2,

ext_cm_CommandLine = 3

} ext_ConnectMode;

enum {

ext_dm_HostShutdown = 0,

ext_dm_UserClosed = 1

} ext_DisconnectMode;




interface _IDTExtensibility2 : IDispatch {


HRESULT OnConnection(

[in] IDispatch* Application,

[in] ext_ConnectMode ConnectMode,

[in] IDispatch* AddInInst,

[in] SAFEARRAY(VARIANT)* custom);


HRESULT OnDisconnection(

[in] ext_DisconnectMode RemoveMode,

[in] SAFEARRAY(VARIANT)* custom);


HRESULT OnAddInsUpdate([in] SAFEARRAY(VARIANT)* custom);


HRESULT OnStartupComplete([in] SAFEARRAY(VARIANT)* custom);


HRESULT OnBeginShutdown([in] SAFEARRAY(VARIANT)* custom);


All COM add-ins inherit from the IDTExtensibility2 interface, and must implement each of its five methods.

OnConnection and OnDisconnection, as their names suggest, are called when the add-in loads and unloads from memory. The add-in can be loaded either during application startup, by the user, or through automation. The enumerator ext_Connect denotes these connection modes. OnAddinsUpdate is called when a set of COM add-ins changes. OnStartupComplete is called only if the add-in was loaded during application startup, and OnBeginShutdown is called if the add-in was disconnected when the host application shutdown.

Registering an add-in

To register the COM add-in with the host application, we also need to create a couple of registry sub keys under the hive


... where ProgID refers to the add-in COM object's unique Programmatic Identifier. The other entries through which the add-in can provide information about itself and specify loading options to the host app are:
  • FriendlyName: The add-in's name as displayed by the host app.
  • Description: Description of the add-in.
  • LoadBehavior: A DWORD combination of values that determine how the add-in will be loaded by the host app. Should be set to 0x03 to load on app startup or 0x08 for user controlled activation.
  • CommandLineSafe: A DWORD value set to 0x01 (TRUE) or 0x00 (FALSE).
For a full description of the all values and options, please consult the MSDN documentation.
blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials