Home Page (Add-ins) | Overview | How Do I ... Topics | FAQ | Reference
In addition to creating add-ins with Visual C++, you can create them with Visual Basic version 4.0 or later. The easiest way to create an add-in with Visual Basic is to start with the sample provided. The sample for Visual Basic version 4.0 is called VB4AddIn, and the sample for Visual Basic versions 5.0 or later is called VB5AddIn.
Add-ins created with Visual Basic version 5.0 (or later) have the following advantages over Visual Basic version 4.0:
Creating an add-in with Visual Basic can be divided into the following steps:
Optionally, after creating an add-in project, you can employ early binding to optimize the add-in's performance.
To copy the sample add-in files
To name and describe the add-in
Note that this project in Visual Basic is a .DLL project type. When you build it, you will build a .DLL.
Once the add-in project is built, this name appears in Visual C++ on the Add-ins and Macros Files tab of the Customize dialog box (Tools menu, Customize Command).
Once the add-in project is built, this description also appears on the Add-ins and Macros Files tab of the Customize dialog box.
To reference the Visual C++ type libraries
For Visual C++ version 5.0, their names begin with "Visual Studio 97." For Visual C++ version 6.0, their names begin with "Visual C++ 6.0."
To customize your add-in, you can modify the code in several ways:
Some of these steps are optional, or contain optional parts.
Your add-in will connect to and disconnect from Developer Studio by using the OnConnection and OnDisconnection methods implemented in the DSAddIn class.
In the samples, the connection code adds one command to the Visual C++ environment. You add more commands by calling the AddCommand method for each command you want to add (see Adding commands to the Visual C++ environment for details).
In the samples, the disconnection code does nothing; however, you might want to modify it to add clean-up code that destroys the objects you create.
The Commands class defines the actions performed by the commands you add to the Visual C++ environment. The samples define one action, which is to display a message box.
This consists of two steps for every command you add: Adding a public procedure to the Commands class, and adding a call to the AddCommand method. Optionally, you can create a toolbar button for the command.
To add a public procedure to the Commands class
To add a call to the AddCommand method
To create a toolbar button for the command
Add event handlers (Visual Basic 5.0 or later)
To create the add-in DLL
Now when you return to Visual C++, the add-in appears on the Add-ins and Macros Files tab of the Customize dialog box (Tools menu, Customize Command). You can select it to view its name and description. You can run the add-in by using the toolbar button or key sequence you assign to it. For more information, see Carrying Out Add-in Commands.
An add-in can employ early binding by using the COM interface. Early binding makes all calls into the interface faster at run time. In Visual Basic, you use early binding by declaring object variables as the appropriate types. For example, the following code accesses text-specific members of an object by declaring the MyTextDoc
variable as TextDocument.
Dim MyDoc as Document
set MyDoc = Application.ActiveDocument
if (MyDoc.Type = "Text") then
Dim MyTextDoc as TextDocument
' VB does an implicit QueryInterface
' for the following set
set MyTextDoc = MyDoc
' Now, you can use text-specific members of
' MyTextDoc
End If