SAMPLE: Comaddin.exe Office 2000 COM Add-In Written in Visual C++ID: Q230689
|
Comaddin.exe is a self-extracting executable that demonstrates building an Office 2000 Component Object Model (COM) add-in in Visual C++. A COM add-in is an in-process COM server (DLL) specifically designed to run within the context of one or more Office 2000 applications. COM add-ins provide a flexible, efficient, and uniform method of extending the Office 2000 environment.
COM add-ins are a new feature of Office 2000. They are built using any programming language that can create COM components, such as Visual Basic, Visual C++, Visual J++, and the Office 2000 Developer Edition of Microsoft Visual Basic for Applications.
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
Software Library:
Comaddin.exeRelease Date: Jan-04-1999
Q119591 How to Obtain Microsoft Support Files from Online Services
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
OnConnection
The 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:
- Application - A reference to the IDispatch interface of the host application.
- ConnectMode - A constant that specifies how the add-in was connected.
- ext_cm_AfterStartup - Started by the end user from the COM add-ins dialog.
- ext_cm_CommandLine - Connected from the command line.
- ext_cm_External - Connected by an external application through Automation.
- ext_cm_Startup - Started by the host at application startup. This behavior can be controlled by a setting in the registry.
- AddInInst - A reference to the COMAddIn object that refers to this add-in in the COMAddIns Collection for the host application.
- Custom - An array of Variants that can hold user-defined data.
OnDisconnection
The 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:
- RemoveMode - A constant that specifies how the add-in was disconnected.
- ext_dm_HostShutdown - Disconnected when the host application closed.
- ext_dm_UserClosed - Disconnected by the end user or an Automation controller.
- Custom - An array of Variants that can hold user-defined data.
OnAddInsUpdate
The 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 OnBeginShutdown
Both 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.
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:
Additional query words:
Keywords : kbfile kbsample kbAutomation kbExcel kbFrontPage kbVC kbPowerPt kbWord kbGrpDSO
Version : :2000; WINDOWS:2000; winnt:5.0,6.0
Platform : WINDOWS winnt
Issue type : kbinfo
Last Reviewed: June 3, 1999