Freigeben über


Visual Basic Concepts

Design Considerations for Add-Ins

Before creating an add-in, you should decide what the goal you want your add-in to accomplish and how you want it to work. Two factors that have an impact on this decision are usage of the CreateToolWindow function, and choosing a project compile type.

CreateToolWindow Function

While not a required add-in feature, the CreateToolWindow function is a feature you may want to consider using for many add-ins. When you create an add-in, any forms it uses are Visual Basic forms by default. While this is fine for most applications, some programmers may desire that the add-in window act as other windows in Visual Basic do and dock with other IDE windows. The way to create windows like this is to use ActiveX documents and the CreateToolWindow function.

A UserDocument window inside a ToolWindow creates an ActiveX document which can dock with existing windows and act like other windows in the Visual Basic IDE. Writing your add-ins to use CreateToolWindow will also aid you in migrating your add-ins to future versions of Visual Basic.

For an example of how CreateToolWindow is used in an add-in, see the following code fragment, taken from the TabOrder sample application (which is listed in the directory):

Dim docTabOrderObject As Object  'user doc instance
' The guidMYTOOL$ constant is the unique registry
' identifier for your add-in.
Const guidMYTOOL$ = "{B7AFC8D0-EBE5-11cf-A497- _
   00A0C911E8B0}"
Set winWindow = _
gVBInstance.Windows.CreateToolWindow(gVBInstance. _
Addins("TabOrder.Connect"), "TabOrder.docTabOrder", _
LoadResString(10), guidMYTOOL$, docTabOrderObject)

The code above creates a Tool Window to hold an ActiveX document.

You can generate your own values for the guid string constant using a tool called Guidgen.exe, which is located in the \tools\idgen directory of Visual Basic.

Choosing a Project Type

Before getting too involved writing an add-in, you should decide how you want to compile the project.

In most situations, you’ll likely want to create and compile your add-ins as ActiveX DLL projects, which are in-process components. As in-process components, they provide better overall performance in Visual Basic.

You may want to compile your add-in as a .dll file if:

  • The add-in will always be used in conjunction with the Visual Basic IDE (or other programming environment that can use Visual Basic-created add-ins).

  • The add-in contains references to certain properties that are available only in Visual Basic.

  • The add-in must run as quickly as possible. ActiveX out-of-process components may perform more slowly than in-process components due to the time involved in marshaling across process boundaries.

You might, however, choose to compile an add-in as an ActiveX .exe file  if you want the add-in to be able to run on its own — independent of Visual Basic — as well as in the Visual Basic environment.

When you use the Add-In template to create your add-in (which is recommended), your project type defaults to ActiveX EXE. You can change the project type on the General tab of the Project Properties dialog box.