Microsoft Office 2000/Visual Basic Programmer's Guide   

Implementing the IDTExtensibility2 Library

A COM add-in has events that you can use to run code when the add-in is loaded or unloaded, or when the host application has finished starting up or shutting down. In order to use these events, you must implement the IDTExtensibility2 library, which provides a programming interface for integrating COM add-ins with their host applications. When you implement the IDTExtensibility2 library within a class module, the library makes a set of new events available to the module. These are the events that you need to control your COM add-in.

If you've created your add-in project from the template, the IDTExtensibility2 library has already been implemented for you in the add-in designer's class module. If you're creating the COM add-in from scratch, use the following procedure.

To manually implement the IDTExtensibility2 library in Visual Basic 6.0

  1. Set a reference to the library by clicking References on the Project menu and then selecting the check box next to Microsoft Add-in Designer. If this library doesn't appear in the list, you can add it by clicking Browse and finding the file Msaddndr.dll. By default this file is located in the C:\Program Files\Common Files \Designer subfolder.

  2. In the Declarations section of the add-in designer's class module, add the following code:
    Implements IDTExtensibility2
    
  3. In the Code window, click IDTExtensibility2 in the Object box. This creates the OnConnection event procedure stub.

  4. Create event procedure stubs for the four remaining event procedures by clicking them in the Procedure box in the Code window.

  5. Add code or a comment to each of the five event procedures.

    Important   You must include the event procedure stub for each event provided by the IDTExtensibility2 interface. If you omit any of the event procedures, your project will not compile. If you're not adding code to an event procedure stub, it's a good idea to add a comment; a single apostrophe (') is sufficient.

For more information about the Implements keyword and implementing libraries in a class module, see Chapter 9, "Custom Classes and Objects."