MS Office Addin creation and related info in vc++

This article describes how to create a simple, compiled add-in that inserts the current date and time at the insertion point. In this article, you create and install an add-in project, load the add-in, and integrate the add-in in the Visual Studio .NET or Visual Studio 2005 interface.

Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you must have:
Microsoft Visual Studio .NET or Microsoft Visual Studio 2005
Microsoft Windows 2000 Professional, Microsoft Windows Server 2003, Microsoft Windows 2000 Server, Microsoft Windows XP Professional, Microsoft Windows XP Server with the Microsoft .NET Framework

On Connection
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 successfully, the add-in is said to be loaded. If an error message is returned, the host application immediately releases its reference to the add-in, and the object is destroyed. OnConnection takes the following four parameters:
Application - A reference to the host application object.
ConnectMode - A constant that specifies how the add-in is connected. The add-in can be connected in the following ways:
ext_cm_AfterStartup - The add-in is started by the end user from the COM Add-ins dialog box.
ext_cm_CommandLine - The add-in is connected from the command line. Note that this does not apply to building COM add-ins for Office applications.
ext_cm_External - The add-in is connected by an external application through Automation. Note that this does not apply to building COM add-ins for Office applications.
ext_cm_Startup - The add-in is started by the host at application startup. This behavior is 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 Variant type values that can hold user-defined data.
OnDisconnection

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 should 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. The add-in can be disconnected in the following ways:
ext_dm_HostShutdown - The add-in is disconnected when the host application closed.
ext_dm_UserClosed - The add-in is disconnected by the end user or an Automation controller.
Custom - An array of Variant type values 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
loadTOCNode(3, 'summary');

Both the OnStartupComplete and the OnBeginShutdown methods are called when the host application has left or is entering a state in which user interaction should be avoided because the application is busy loading or unloading itself from memory. OnStartupComplete is only called if the add-in was connected during startup, and OnBeginShutdown is only called if the host disconnects the add-in 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.

COM Add-in Registration


In addition to normal COM registration, a COM add-in needs to register itself with each Office application in which it runs. To register itself with a particular application, the add-in should create a subkey, using its ProgID as the name for the key, under the following location:
HKEY_CURRENT_USER\Software\Microsoft\Office\OfficeApp\Addins\ProgIDThe 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 by using a DWORD value called LoadBehavior. This value determines how the add-in is loaded by the host application, and is made up of a combination of the following values:
0 = Disconnect - Is not loaded.
1 = Connected - Is loaded.
2 = Bootload - Load on application startup.
8 = DemandLoad - Load only when requested by user.
16 = ConnectFirstTime - Load only once (on next startup).The typical value specified is 0x03 (Connected Bootload). Add-ins that implement IDTExtensibility2 should also specify a DWORD value called CommandLineSafe to indicate whether the add-ins are safe for operations that do not support a user interface. A value of 0x00 indicates False, and a value of 0x01 indicates True.

How to Build a COM Add-in by Using Visual Basic .NET
loadTOCNode(2, 'summary');

As mentioned earlier, an Office COM add-in is an in-process COM server that is activated by an Office application through the COM run-time layer. Therefore, developing a COM add-in in Visual Basic .NET requires that the add-in component be implemented in .NET and then exposed to the COM clients (that is, the Office applications) through the COM interop layer.To create a COM add-in in Visual Basic .NET, follow these steps:
In Visual Basic .NET, create a Class Library project.
Add a reference to the type library that implements IDTExtensibility2. The primary interop assembly for this is already available under the name Extensibility.
Add a reference to the Microsoft Office object library. The primary interop assembly for this is already available under the name Office.
Create a public class in the class library that implements IDTExtensibility2.
After the class library is built, register the library for COM interop. To do this, generate a strong named assembly for this class library and then register it with COM interop. You can use Regasm.exe to register a .NET component for COM interop.
Create registry entries so that Office applications can recognize and load the add-in.You can choose to complete all of these steps, or you can create a .NET project of type Shared Addin. This starts the Extensibility Wizard, which helps you to create a COM add-in in .NET. The Extensibility Wizard creates a Visual Basic .NET class library project along with a Connect class that implements the IDTExtensibility2 interface. The skeleton code that implements the empty members of IDTExtensibility is also generated. This project has references to Extensibility and Office assemblies. The build settings of the project have Register for COM Interop selected. The assembly key (.snk) file is generated and is referenced in the AssemblyKeyfile attribute in Assemblyinfo.vb. Along with the class library project, the wizard generates a setup project that you can use to deploy the COM add-in on other computers. You may remove this project if desired.

Comments

Popular posts from this blog

XML Programming using IXMLDOMDOCUMENT in vc++

Get correct OS version on win 8.1 without using GetVesionEx API (deprecated )