References.AddActiveX(String, Int32, Int32, Int32, String) Method

Definition

Adds a reference to an ActiveX type library.

VSLangProj::Reference AddActiveX(std::wstring const & bstrTypeLibGuid, int lMajorVer = 0, int lMinorVer = 0, int lLocaleId = 0, std::wstring const & bstrWrapperTool = "");
[System.Runtime.InteropServices.DispId(7)]
public VSLangProj.Reference AddActiveX (string bstrTypeLibGuid, int lMajorVer = 0, int lMinorVer = 0, int lLocaleId = 0, string bstrWrapperTool = "");
[<System.Runtime.InteropServices.DispId(7)>]
abstract member AddActiveX : string * int * int * int * string -> VSLangProj.Reference
Public Function AddActiveX (bstrTypeLibGuid As String, Optional lMajorVer As Integer = 0, Optional lMinorVer As Integer = 0, Optional lLocaleId As Integer = 0, Optional bstrWrapperTool As String = "") As Reference

Parameters

bstrTypeLibGuid
String

Required. The type library's globally unique identifier (GUID), expressed as a string.

lMajorVer
Int32

Optional. The major version number. If omitted, 0 is used.

lMinorVer
Int32

Optional. The minor version number. If omitted, 0 is used.

lLocaleId
Int32

Optional locale id. For more information, see LocaleID.

bstrWrapperTool
String

The wrapper tool to be used when generating an assembly wrapper for the type library. The supported values are described in the following table. [1|1] Value[1|2] Result[2|1] "tlbimp"[2|2] The project system generates a generic wrapper suitable for accessing the COM object's methods and properties.[3|1] "aximp"[3|2] The project system generates a wrapper that Windows forms uses for ActiveX hosting. [4|1] "" (empty string)[4|2] The project system checks if a primary interoperability assembly for the specified type library exists. If found, then that assembly is used as the wrapper for the COM object's methods and properties. If not found, the behavior is the same as if "tlbimp" were specified.

Returns

Returns a Reference object for the requested ActiveX library object.

Attributes

Examples

' Macro Editor  
' Add a reference to the ActiveX Data Objects Library, Version 2.5  
Imports VSLangProj  
Public Sub AddARef()  
   Try  
      Dim proj As VSLangProj.VSProject = _  
         CType(DTE.Solution.Projects.Item(1).Object, _  
         VSLangProj.VSProject)  
      ' GUID for ActiveX Data Objects, version 2.5  
      proj.References.AddActiveX( _  
      "{00000205-0000-0010-8000-00AA006D2EA4}", 2, 5)  
   Catch ex As System.Exception  
      MsgBox("Cannot add that reference.")  
   End Try  
End Sub  

Remarks

The AddActiveX method adds references to a project for the specified object and any dependencies listed by the object. Therefore, one call to this method may result in more than one reference being added to the References collection.

The valid format for a GUID is "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", where X is a hexadecimal digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). One method for determining the GUID for an ActiveX object is to view the .ocx or .tlb file using the Oleview.exe tool distributed with Visual Studio.

An error is generated if a reference with the same identity is already in the collection.

If you receive a "Library not registered" error when referencing a valid COM object, then it is likely due to the fact that you are not passing a valid lMajorVer parameter value to the AddActiveX method. By default, AddActiveX uses a value of 0 for everything but the GUID. If the version of the COM object is, for example, 1, the call will fail because there is no registered version 0 of the typelib. For example, when calling version 1.0 of the Windows Media player

ref = refColl.AddActiveX("{22D6F304-B0F6-11D0-94AB-0080C74C7E95}")

produces the aforementioned error, but

ref = refColl.AddActiveX("{22D6F304-B0F6-11D0-94AB-0080C74C7E95}", 1)

works correctly.

This method will add a registered type library only. A call is made to QueryPathOfRegTypeLib, an Automation (formerly OLE Automation) API function, passing the information supplied to the AddActiveX method.

If the file name of the ActiveX object is known, the object may be added by using the Add. The Add method does not require the GUID, version, or locale ID.

To remove a reference, use the Remove.

For more information on COM object wrappers, ActiveX hosting, and primary interoperability assemblies, see Tlbimp.exe (Type Library Importer) and Aximp.exe (Windows Forms ActiveX Control Importer).

Applies to