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.
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.
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.