Extensibility.IDTExtensibility2

A COM Add-in is an in-process COM server (an ActiveX DLL) that must implement the Microsoft.Office.Core.IDTExtensibility2 interface.
All COM add-ins must implement the IDTExtensibility2 interface and it is this interface that is used by all Office applications to communicate with COM add-ins.
All COM Add-ins must implement the following five methods of this interface:
https://msdn.microsoft.com/en-us/library/aa537182.aspx


OnConnection

This method is called when the COM add-in is loaded into the application.
The add-in might be connected on startup, by the user, or through Automation (changing the Connect property to true)

void Extensibility.IDTExtensibility2.OnConnection( 
   object Application,
   Extensibility.ext_ConnectMode ConnectMode,
   object AddInInst,
   ref System.Array custom)

Application - provides a reference to the Application object which the COM add-in can then use
ConnectMode - specifies how the add-in was loaded (ext_ConnectMode enumeration)
AddinInst - provides a COM add-in object which refers to the instance of the class module which code is currently running. Used to return the programmatic identifier for the add-in.
Custom - a variant array providing additional information.


OnDisconnection

This method is called when the COM add-in is unloaded from the application.
This also occurs when the application in closed.
The add-in should perform any cleanup of resources in this event and restore any changes made to the host.
The add-in might be disconnected when the application exits, by the user or through Automation.

void Extensibility.IDTExtensibility2.OnDisconnection( 
   Extensibility.ext_DisconnectMode RemoveMode,
   ref System.Array custom)

RemoveMode - specifies how the add-in was unloaded (ext_DisconnectionMode enumeration)
Custom - a variant array providing additional information.


OnStartupComplete

This method is called when the application has finished starting up and has loaded the COM add-in that was registered to load at startup.
Whenever a COM add-in is installed or removed from the host application, this event fires.
If the add-in is not loaded at startup then this event does not fire
If the add-in is loaded this event occurs after the OnConnection event.

void Extensibility.IDTExtensibility2.OnStartupComplete(ref System.Array custom) 

Custom - a variant array providing additional information.


OnBeginShutdown

This method is called when the application is closed and the add-in is still loaded.
If the add-in is not loaded when the application is closed this event does not fire
If the add-in is loaded when the application is closed this event occurs before the OnDisconnection event.

void Extensibility.IDTExtensibility2.OnBeginShutdown(ref System.Array custom) 

Custom - a variant array providing additional information.


OnAddinsUpdate

This method is called when ANY COM add-in is loaded or unloaded in the Office application.
The custom parameter is not set by any of the Office applications.
You can only use the Application.COMAddins collection to check what has been loaded or unloaded.
Called if the add-in was connected during startup. At the point when this method is called, the host application's UI is fully active.

void Extensibility.IDTExtensibility2.OnAddInsUpdate(ref System.Array custom) 

Custom - a variant array providing additional information.


Interface Equivalent

internal interface MyIDTExtensibility2 
{
    [System.Runtime.InteropServices.DispId(1)]
    void OnConnection(
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.IDispatch)] object Application,
        [System.Runtime.InteropServices.InAttribute] ext_ConnectMode ConnectMode,
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.IDispatch)] object AddInInst,
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType = System.Runtime.InteropServices.VarEnum.VT_VARIANT)] ref System.Array custom);

    [System.Runtime.InteropServices.DispId(2)]
    void OnDisconnection(
        [System.Runtime.InteropServices.InAttribute] ext_DisconnectMode RemoveMode,
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType = System.Runtime.InteropServices.VarEnum.VT_VARIANT)] ref System.Array custom);

    [System.Runtime.InteropServices.DispId(3)]
    void OnAddInsUpdate(
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType = System.Runtime.InteropServices.VarEnum.VT_VARIANT)] ref System.Array custom);

   [System.Runtime.InteropServices.DispId(4)]
   void OnStartupComplete(
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType = System.Runtime.InteropServices.VarEnum.VT_VARIANT)] ref System.Array custom);

    [System.Runtime.InteropServices.DispId(5)]
   void OnBeginShutdown(
        [System.Runtime.InteropServices.InAttribute] [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.SafeArray, SafeArraySubType = System.Runtime.InteropServices.VarEnum.VT_VARIANT)] ref System.Array custom);
}

    public enum ext_ConnectMode
    {
        ext_cm_AfterStartup = 0,
        ext_cm_Startup = 1,
        ext_cm_External = 2,
        ext_cm_CommandLine = 3,
        ext_cm_Solution = 4,
        ext_cm_UISetup = 5,
    }

    public enum ext_DisconnectMode
    {
        ext_dm_HostShutdown = 0,
        ext_dm_UserClosed = 1,
        ext_dm_UISetupComplete = 2,
        ext_dm_SolutionClosed = 3,
    }


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext