Article ID: 230689 - View products that this article applies to.
This article was previously published under Q230689
Comaddin.exe is a self-extracting executable that demonstrates building an Office 2000 or Office XP Component Object Model (COM) add-in using Visual C++. A COM add-in is an in-process COM server specifically designed to run within the context of one or more Office 2000 or Office XP applications. COM add-ins provide a flexible, efficient, and uniform method of extending the Office environment.
COM add-ins are built using any programming language that can create COM components, such as Visual Basic, C/C++, C# , and the Office 2000 Developer or Office XP Developer edition of Microsoft Visual Basic for Applications (VBA).
This sample demonstrates the necessary steps to build a COM add-in in Visual C++. The sample creates a basic add-in shell that you can extend to build your own Office add-in.
The following file is available for download from the Microsoft Download Center:
Comaddin.exeRelease Date: January 4, 1999
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
(http://support.microsoft.com/kb/119591/EN-US/ )How to Obtain Microsoft Support Files from Online Services
Sample File InformationComaddin.exe extracts the following files to a folder of your choosing:
FileName Size ---------------------------------------- TestAddin.dsw 541 bytes TestAddin.dsp 4.11 KB ComAddin.h 6.19 KB ComAddin.cpp 8.38 KB ComAddin.def 205 bytes MyAddin.cpp 10.6 KB MyAddinCF.cpp 2.18 KB BttnHandler.cpp 6.27 KB
IDTExensibility2For a COM object to be an Office add-in, it must support the IDTExensibility2 interface as described in the Microsoft Add-In Designer Type Library (Msaddndr.dll). This interface has been declared for you in ComAddin.h so no import is necessary. All COM add-ins inherit from this interface and must implement each of its five methods:
OnConnectionThe OnConnection event fires whenever the COM add-in is connected. The add-in may be connected on startup, by the end user, or through automation. If OnConnection returns S_OK, the add-in is said to be loaded. If any other value is returned, the host application will immediately release its reference to the add-in and the object will be destroyed.
OnConnection takes the following four parameters:
OnDisconnectionThe OnDisconnection event fires when the COM add-in is disconnected and just before it unloads from memory. The add-in should perform any cleanup of resources in this event, and restore any changes made to the host application.
OnDisconnection takes the following two parameters:
OnAddInsUpdateThe OnAddInsUpdate event fires when the set of registered COM add-ins changes. In other words, whenever a COM add-in is installed or removed from the host application, this event fires.
OnStartupComplete and OnBeginShutdownBoth the OnStartupComplete and OnBeginShutdown events notify the add-in when the host application has left or is entering a state where user-interaction should be avoided because the application is busy loading or unloading itself from memory. OnStartupComplete will only fire if your add-in was connected during startup, and OnBeginShutdown will only fire if your add-in is disconnected by the host during shutdown.
Because the user-interface for the host application is fully active when these events fire, they may be the only way to perform certain actions that otherwise would be unavailable from OnConnection and OnDisconnection.
Registering the COM Add-InIn addition to normal COM registration, a COM add-in needs to register itself with each Office 2000 application in which it can safely run. To register itself with a particular application, the add-in creates a subkey, using its ProgID as the name for the key, under the following location:
HKEY_CURRENT_USER\Software\Microsoft\Office\<AppName>\Addins\<AddInProgID>The add-in can provide values at this key location for both a friendly display name and a full description. In addition, the add-in should specify its desired load behavior using a DWORD value called "LoadBehavior." This value determines how the add-in will be loaded by the host application, and is made up of a combination of the following values:
Add-ins that implement IDTExtensibility2 should also specify a DWORD value called "CommandLineSafe" to indicate whether they are safe for operations that do not support a user interface. A value of 0x00 means False, 0x01 is True. Because this sample displays a message box, it is not safe for command line execution, and therefore sets the value to 0x00.
Getting StartedTo get started writing add-ins, compile the sample project, run regsvr32.exe on the built DLL, and then launch Microsoft Word, Excel, Powerpoint and/or Frontpage 2000. You should see a dialog box open as the add-in gets loaded that says "Hello" and tells you what application it is in.
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Richard R. Taylor, Microsoft Corporation.
Article ID: 230689 - Last Review: August 9, 2004 - Revision: 5.4