Packaging and Deploying Your COM Add-In

Users commonly interact with setup programs to install new applications and components on their computers. When your COM add-in is ready to be distributed to other users, you can use the Package and Deployment Wizard that's installed by Visual Basic 6.0 or Office 2000 Develper. The Package and Deployment Wizard allows you to create a setup program that you supply to your users so that they can install your add-in.

Depending on the initial load behavior of the add-in, the next rime a user starts an Office application that the add-in targets, the add-in will be available. The following example steps through the use of the Package and Deployment Wizard in order to package the basic COM add-in created in this chapter.

NOTE
Before you package and deploy your COM add-in, make sure the initial load behavior of your COM add-in is set appropriately; that is, according to the functionality the add-in provides.

Package the Basic COM Add-In

  1. Load the Visual Basic project that represents your basic COM add-in. Exit Word and Excel if they running.
  2. Click the File menu, and then click Make BasicCOMAddIn.dll. In the Make Project dialog box, click OK. (This step isn't necessary if you compiled your COM add-in project into a .dll.)
  3. From the Windows Start menu, navigate to the Microsoft Visual Basic 6.0 folder in the Programs menu. Click Microsoft Visual Basic 6.0 Tools, and then click Package & Deployment Wizard. The Package and Deployment wizard is displayed.
  4. Click to view at full size.

  5. Click the Browse button next to the "Select project" text box and navigate to your COM add-in project. Click OK.
  6. Click the Package button below the "Select project" text box. If you haven't compiled your project into a .dll, the wizard will display the dialog box on the following page, indicating that the project needs to be compiled. If necessary, click Compile.
  7. If the source files are newer than the previously compiled project, the wizard displays a dialog box indicating that the source files are newer and asks if you want to recompile. If you want the latest changes in your packaged solution, click Yes.

    Click to view at full size.

    If a compiled file exists and is the most up-to-date, the Package and Deployment wizard displays another dialog box with a series of steps. The first step is selecting a package type.

  8. In the Package Type list box, select Standard Setup Package. As described in the Description text box below the Package Type list box, this creates a package that will be installed by a setup.exe program.
  9. Click to view at full size.

  10. Click Next. In the Package Folder step, create a new folder or select a folder where the package will be assembled on your machine.
  11. Click to view at full size.

    In most cases, the best place to place the package is in a subfolder named Package in the folder containing your compiled .dll and source files. The Package and Deployment wizard automatically selects this folder by default.

  12. Click Next. In the Missing Dependency Information dialog box, click OK. For more information on the Missing Dependency Information dialog box, click the Help button in the dialog box. Clicking OK tells the wizard to proceed without the dependency information for the listed files.
  13. In the Included Files dialog box, make sure that only the following files are selected:
  14. The file associated with the file listed as VB6 Runtime and OLE Automation is Msvbvm60.dll. You don't need to redistribute this file because Office always installs it. Its size is 1.3MB, and it will add to the size of the package that the wizard creates.

    Click to view at full size.

    Often, other files listed in this dialog box are object libraries. If you made a reference to any of the Office object libraries, including any of the following, it will appear in the dialog box:

    If these files are listed, clear them. (Because they're part of the Office install, your package doesn't need to redistribute them.)

NOTE
If you are using a service pack of Visual Basic 6.0 or a service release of Office 2000, you may find that your machine has a newer version of the VB6 Runtime file Msvbvm60.dll than your user's machine. The newer version of the VB6 Runtime file may have some fixes that your COM add-in requires. Make sure you fully test your add-in with the Office application. If you find that your add-in doesn't work for some reason on another user's machine (one that doesn't have Visual Basic 6.0 installed), package the VB6 Runtime from your installation of Visual Basic.

  1. Click Next twice. In the Installation Title step, type in any name that you want to appear in the setup screen that's displayed when the user starts the setup.exe program. The Cab Options step is skipped. By default, it is set to package the COM add-in into a single CAB file.
  2. Click Next twice. In the Install Locations step, add the text \BasicCOM-AddIn after the text $(ProgramFiles) in the Install Location field.
  3. Click to view at full size.

    The string $(ProgramFiles) represents a token indicating the Program Files folder. Setup uses the token because the full path to the Program Files folder on the user's machine may differ. The subfolder information added to $(ProgramFiles) indicates that the subfolder BasicCOMAddIn will be created and the files will be copied to that location.

    Note that the Start Menu Items step is skipped. This step allows you to list items that would appear on the Windows Start menu after setup is complete. But because your COM add-in is loaded only through Office, no items are required on the Start menu.

  4. Click Next twice. In the Finish step, enter a name in the Script name text box and click Finish.
  5. The script is a file that saves the settings made in the Package and Deployment wizard. The script is useful the next time you need to create a package containing the exact same files and settings—but with a newly compiled COM add-in .dll file.

  6. In the Packaging Report dialog box, click Save Report, click Save, and then click Close.
  7. The report saved is a text file containing information about where your package is found and about a batch file that allows you to recreate the cab file quickly when you make changes to some of the files.

  8. Click Close to close the Package and Deployment wizard.

On the location specified in the Package folder step of the wizard, you'll find a CAB file, a Setup.exe file and Setup.lst. The Setup.exe program requires the LST file. The CAB file contains all of the files associated with your COM add-in, along with other files the setup program requires.

Installing the COM Add-In on Another Machine

  1. Copy the three files onto another user's machine and run the Setup.exe program. The setup program begins like most other standard setup programs. Note that the installation title is displayed at the top left of the setup screen as well as in the caption of the first dialog box that's displayed. It's also displayed in the first paragraph in the dialog box, in the line beginning with "Welcome."
  2. Click OK. Click the Click Here to Begin Setup button, as shown in the figure below.
  3. Most users won't change the default directory listed. This directory is the one you entered in the Install Locations step of the wizard.

    Click to view at full size.

  4. Click OK. Your COM add-in is now installed on the user's machine.
  5. Start Word or Excel. A message box is displayed indicating that the add-in is connected and the custom menu item Button1 is added to the Tools menu. Your add-in has now been packaged and deployed onto a user's machine.