RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Adding a Reference to a COM Server
To Add a Reference to a COM Server

  1. In the Project Manager, right-click the References tree node of your project, and select Add Reference.
  2. In the Add Reference dialog box, click the COM Imports tab. The IDE will scan the system registry for all registered type libraries and COM servers.
  3. Select the item or items you want to reference in your project.
    Tip: You can individually select multiple items from the list by holding down the CTRL
    key as you click each item. To select a range of items, select the first item, then hold down the SHIFT key as you select the second item.
  4. Click the Add Reference button. All of the items you selected will appear in the New References list in the bottom portion of the dialog.
    Tip: You can remove items from the New References
    list. Select the item or items and click the Remove button.
  5. If the COM component you want to reference does not appear in the list, click the Browse button to add an explicit reference to it.
  6. In the Select a reference dialog box, navigate to the folder where the component is located.
  7. Select it, and click Open.
  8. When you have selected all of the COM servers you wish to add, click OK.
After you click the OK button in the Add Reference dialog, the IDE will generate interop assemblies for each item you selected (unless a Primary Interop Assembly has already been created). These assemblies will be named Interop.LibraryName.dll, where LibraryName is the name of the component's type library (note this name might differ from the control's DLL file name). The generated assemblies will be stored in a folder called COMImports, under your project directory. Each generated interop assembly will be set to Copy Local, meaning, when the project is built, the assembly will be copied to the build target folder automatically.  

The COMImports folder might not exist, for example, if you move the project to a new machine, or if you delete it on the machine where the project resides. If the COMImports folder does not exist when the project is reopened, the IDE will recreate it and regenerate the interop assemblies. In order for this to work, the COM servers must first be registered on the machine where the project resides.  

If a Primary Interop Assembly for the COM server exists, the IDE will not generate a new interop assembly. Instead a reference to the Primary Interop Assembly will be added, and the Copy Local setting will be turned off, since Primary Interop Assemblies are deployed in the Global Assembly Cache.

Note: To see the Copy Local setting on any referenced assembly, right click the mouse on the assembly in the Project Manager
. The Copy Local setting is an item on the context menu. The project will still retain references to the interop assemblies, even if the COMImports folder could not be regenerated. In this case, the Project Manager will highlight the referenced assembly to indicate that it currently does not exist on the machine.

COM Interop Overview 

Adding an ActiveX Control to the Tool Palette

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!