Visual Studio Automation and Extensibility Reference
IDTExtensibility2.OnConnection Method

Occurs whenever an add-in is loaded into Visual Studio.

Namespace: Extensibility
Assembly: Extensibility (in extensibility.dll)

Syntax

Visual Basic (Declaration)
Sub OnConnection ( _
    <InAttribute> Application As Object, _
    <InAttribute> ConnectMode As ext_ConnectMode, _
    <InAttribute> AddInInst As Object, _
    <InAttribute> ByRef custom As Array _
)
Visual Basic (Usage)
Dim instance As IDTExtensibility2
Dim Application As Object
Dim ConnectMode As ext_ConnectMode
Dim AddInInst As Object
Dim custom As Array

instance.OnConnection(Application, ConnectMode, AddInInst, custom)
C#
void OnConnection (
    [InAttribute] Object Application,
    [InAttribute] ext_ConnectMode ConnectMode,
    [InAttribute] Object AddInInst,
    [InAttribute] ref Array custom
)
C++
void OnConnection (
    [InAttribute] Object^ Application, 
    [InAttribute] ext_ConnectMode ConnectMode, 
    [InAttribute] Object^ AddInInst, 
    [InAttribute] Array^% custom
)
J#
void OnConnection (
    /** @attribute InAttribute() */ Object Application, 
    /** @attribute InAttribute() */ ext_ConnectMode ConnectMode, 
    /** @attribute InAttribute() */ Object AddInInst, 
    /** @attribute InAttribute() */ /** @ref */ Array custom
)
JScript
JScript does not support passing value-type arguments by reference.

Parameters

Application

A reference to an instance of the integrated development environment (IDE), DTE, which is the root object of the Visual Studio automation model.

ConnectMode

An ext_ConnectMode enumeration value that indicates the way the add-in was loaded into Visual Studio.

AddInInst

An AddIn reference to the add-in's own instance. This is stored for later use, such as determining the parent collection for the add-in.

custom

An empty array that you can use to pass host-specific data for use in the add-in.

Remarks

OnConnection is the main method for IDTExtensibility2, because it is called every time an add-in is loaded. It is the entry point for an add-in when it is loaded, so you can put any code here (or call any another function) that you want to run when the add-in starts.

Example

Visual Basic
Public Sub OnConnection(ByVal application As Object, ByVal _
connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
    MsgBox("Add-in is connected.")
End Sub
C#
public void OnConnection(object application, ext_ConnectMode 
connectMode, object addInInst, ref Array custom)
{
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    System.Windows.Forms.MessageBox.Show("Add-in has connected.");
}
See Also

Tags :


Community Content

Craig Skibo - MSFT
custom parameter values
Visual Studio does not use the custom parameter to pass values to an Add-in. Some Microsoft Office applications, which also use IDTExtensibility2 for implementing Add-ins, do pass values through this parameter for use by the Add-in, but Visual Studio does not.
Tags :

Page view tracker