Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Visual Basic Extensibility Reference

Visual Studio 6.0

OnConnection Method

See Also   Example   Applies To

Occurs when an add-in is connected to the Visual Basic IDE, either through the Add-In Manager dialog box or another add-in.

Syntax

object. IDTExtensibility_OnConnection (vbinst As Object, connectmode As vbext_ConnectMode, addininst As AddIn, custom() As Variant)

The OnConnection method syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
vbinst An object representing the instance of the current Visual Basic session.
connectmode An enumerated value of type vbext_ConnectMode, as specified in Settings.
addininst An AddIn object representing the instance of the add-in.
custom() An array of variant expressions to hold user-defined data.

Settings

The settings for connectmode (vbext_ConnectMode) are:

Constant Value Description
vbext_cm_AfterStartup 0 Add-in was started after the initial Open Project dialog box was shown.
vbext_cm_Startup 1 Add-in was started before the initial Open Project dialog box was shown.
vbext_cm_External 2 Add-in was started externally by another program or component.

Remarks

This method is part of the IDTExtensibility interface, which you should implement in the class that provides your connection object.

Important   Don't directly enter the syntax given above. Instead, use the Implements statement to generate the appropriate method template for the interface. To do this, in the Declarations section of the Class module that provides your add-in's connection object, enter:

Implements IDTExtensibility

After adding this line, you can then select IDTExtensibility from the module's Object drop down box. Select each method from the Procedure drop down to get the procedure template shown above in Syntax. Notice that the necessary code is automatically added to the Class module.

An interface's methods are exposed through the Implements statement. When the above syntax is entered in the Declarations section of the Class module that handles an add-in's events, the interface's methods become available for your use through the module's Procedure and Object drop down boxes. To add the code to the module, select the method from the Procedure drop down box.

Note   While the OnConnection method is a method to the IDTExtensibility interface, to you as a Visual Basic programmer it acts and behaves like an event. In other words, when an add-in is connected to the Visual Basic IDE, either through the Add-In Manager dialog box or another add-in, any code in the OnConnection method automatically occurs, just as if it were an event procedure.

Important   Since an interface is a contract between an object and Visual Basic, you must be sure to implement all of the methods in the interface. This means that all four IDTExtensibility interface methods are present in your Class module, each containing at least one executable statement. This can consist of as little as a single remark statement, but they must each contain at least one executable statement to prevent the compiler from removing them as empty procedures.

Show:
© 2015 Microsoft