Adding, Associating, and Deleting COM Objects

See Also

You use the Associations editor to register COM objects that are installed with your product in Microsoft® Visual Studio® Installer. By adding COM objects and establishing their required associations in the Associations editor, you make it possible for the Microsoft® Windows® installer to register the COM objects on the target machine. Registering installed COM objects with the Windows installer increases the resiliency of your installation.

Registering installed COM objects in a manner compliant with Windows installer requirements makes it possible for your users to rollback COM object installation and registration if the product installation fails. Windows installer registration of COM objects also facilitates advertising COM objects on the target machine. For these reasons, registering COM objects with the Windows installer is recommended over self-registering COM objects at installation. (Self-registering installed COM objects was a common strategy in traditional scripted setup procedures, but the advent of the Windows installer overrides the advantages of self-registration.)

For more information about the benefits of registering COM objects in a Windows installer-compliant manner, see Installer Associations.

This topic explains how to:

Before adding COM objects

You can only add existing COM objects to an installer project; you do not create the COM object in the installer project. To add an existing COM object to an installer project, you must know the class identifier (CLSID) of the COM object. Several strategies are available for determining the CLSID of a COM object.

To find the CLSID for an object from Do this
Microsoft® Visual Basic® or a third-party control you do not have source code for Use the Visual Studio OLE/COM Object Viewer.

For more information, search for "OLE/COM Object Viewer" in the MSDN™ Library (Entire Collection).

Note   When you create a sharable COM object in Visual Basic, you should use the Binary Compatibility option to preserve its CLSID between versions. For more information, search for "binary compatibility" in the MSDN Library Visual Basic Documentation.

Microsoft® Visual C++® Use the Visual C++ Object Viewer or examine the appropriate header (.h) file for the COM object entry.

For more information about the Object Viewer, search for "OLE/COM Object Viewer" in the MSDN Library (Entire Collection).


To add COM objects

  1. Find the class identifier (CLSID) for the COM object you are adding to the installer project. For information about how to do this, see Before adding COM objects.

  2. Add the file containing the COM object to be installed to your installer project. (For example, a Visual Basic COM object would be contained in a Microsoft® ActiveX® .dll file.)

    For information about adding files to an installer project, see Adding Files to an Installer Project and Adding Merge Modules to an Installer Project.

  3. Select the file containing the COM object in the File System editor, and make sure its Register property is set to 0 - vsifrNone. (You can set file properties in the Properties window.) This ensures the COM object will not self-register on installation.

    For information about working in the File System editor, see File System Editor and Managing Components, Files, and Folders in an Installer Project. For information about setting file properties, see File Properties.

  4. Display the Associations editor. (You can do this by expanding the Target Machine node in the Project Explorer window and then double-clicking Associations.)

  5. Right-click anywhere in the Associations editor.

  6. Select Add COM Object from the context menu.

    A new COM object is added to your project with a default CLSID and shown in the COM Objects node in the Associations editor.

  7. Change the default CLSID by typing over it. You can also change a CLSID by entering a new one in the CLSID property (in the Properties window) for the selected COM object.

    Important   You must change the COM object CLSID to the CLSID that matches the COM object you are adding to the project. For information about looking up the CLSID for COM objects, see Before adding COM objects.

    CAUTION   For Visual Basic COM objects only, Visual Basic may change the CLSID even if you have set the Binary Compatibility option to preserve the CLSID. That is, Visual Basic may disregard the Binary Compatibility option for the COM object and reset its CLSID. If this happens, you must start again at Step 1 of this procedure to find and use the current CLSID for the Visual Basic COM object.

  8. To make sure the Windows installer can correctly install and register the COM object, you must associate it with a type library. You can also associate COM objects with document types and installer components.

    For more information, see To associate COM objects with type libraries and document types.

Before establishing COM object associations

Before you can associate a COM object with a type library or document type, each element you will associate must already be part of the installer project. For more information about adding these items to an installer project, see:

To associate COM objects with type libraries and document types

  1. Make sure the elements necessary for the association have been added to the installer project. For information about adding the elements necessary for COM object associations, see Before establishing COM object associations.

  2. Display the Associations editor.

  3. In the Associations editor, expand the COM Objects node to show the COM object you want to associate with a type library or document type.

  4. In the COM Objects node, select the COM object you want to associate with a type library or document type.

  5. Establish the desired association, as follows:
To establish this association with a selected COM object Modify this property in the Properties window
A type library The Component property of the COM object so it matches the Component property of the associated type library. This file contained the COM object external to Visual Studio Installer. (For example, a Visual Basic COM object would be contained in an ActiveX .dll file.)

For more information about the COM object and type library component property, see COM Object Properties and Type Library Properties.

A document type The COMObject property of the document type you are associating so it matches the CLSID property of the COM object.

For more information about the document type COMObject property, see Document Type Properties. For more information about the COM object CLSID property, see COM Object Properties.


To delete COM Objects

  1. Display the Associations editor.

  2. If necessary, expand the COM Objects node to show the COM object you want to delete.

  3. In the COM Objects node, right-click the COM object you want to delete.

  4. Select Delete from the context menu.

    The COM Objects node shows the COM object has been deleted from the installer project. This COM object will not be installed or registered with your product.