Home Page (Add-ins) | Overview | How Do I ... Topics | FAQ | Reference
When Visual C++ starts, it automatically loads all add-ins checked on the Add-ins and Macro Files tab of the Customize dialog box (Tools menu, Customize command). Visual C++ loads each add-in by calling the OnConnection method exposed by the add-in's DSAddIn object. This method also makes the commands exposed by the add-in available for the user to carry out, and it connects the add-in to Developer Studio events if the add-in contains event handlers.
When Visual C++ quits, it unloads each add-in by calling the OnDisconnection method exposed by the add-in's DSAddIn object.
Each add-in exposes a DSAddIn object and a Commands object. The Visual C++ Developer Studio environment uses the DSAddIn object to connect to or disconnect from an add-in, and it uses the Commands object to carry out a command added by the AddCommand method.
An add-in exposes the DSAddIn object by implementing the COM IDSAddIn interface or the IDispatch IDispDSAddIn interface. An add-in written in Visual Basic version 4.0 must implement the IDispatch interface.
The COM interface is early bound by Developer Studio, whereas the IDispatch interface is late bound. The advantage of using the COM interface is that its early binding makes all calls into the interface faster at run time.
Note IDSAddIn is not a dual interface because it does not derive from IDispatch. It derives from IUnknown.
If an add-in provides a COM interface to its DSAddIn object, Developer Studio chooses it; otherwise, Developer Studio chooses an IDispatch interface. If neither interface is available, Developer Studio does not connect to the add-in.
To implement the COM interface, add-ins must use the following predefined Interface ID (IID), which is declared in Microsoft Visual Studio\VC98\Include\ObjModel\AddGuid.h:
// {C0002F81-AE2E-11cf-AD07-00A0C9034965}
DEFINE_GUID(IID_IDSAddIn,
0xc0002f81, 0xae2e, 0x11cf, 0xad, 0x7, 0x0, 0xa0, 0xc9, 0x3, 0x49, 0x65);
If you use the Developer Studio Add-in Wizard, it automatically generates the code to implement the COM interface. Similarly, if you use Visual Basic version 5.0 or later, the sample add-in includes this code.
Each add-in exposes a DSAddIn object and a Commands object. Developer Studio uses the DSAddIn object to connect to or disconnect from an add-in, and it uses the Commands object to carry out a command added by the AddCommand method.
The Commands object exposes a method for each command added by AddCommand. This method specifies what the command does. You must write the code for the method.
If you use Visual C++, you can implement the Commands object by using the Developer Studio Add-in Wizard. This wizard automatically generates code for one method; however, if you need more methods you must add the code for them. For details, see Adding Commands to the Visual C++ Developer Studio.
If you use Visual Basic version 4.0 or later, you can implement the Commands object by copying code from the samples provided. However, each sample includes code for only one method, which displays a simple message box. If you need more methods, you must add the code for them.