Compartilhar via


References.AddActiveX Method

Adds a reference to an ActiveX type library.

Namespace:  VSLangProj
Assembly:  VSLangProj (in VSLangProj.dll)

Syntax

'Declaration
Function AddActiveX ( _
    bstrTypeLibGuid As String, _
    lMajorVer As Integer, _
    lMinorVer As Integer, _
    lLocaleId As Integer, _
    bstrWrapperTool As String _
) As Reference
Reference AddActiveX(
    string bstrTypeLibGuid,
    int lMajorVer,
    int lMinorVer,
    int lLocaleId,
    string bstrWrapperTool
)
Reference^ AddActiveX(
    [InAttribute] String^ bstrTypeLibGuid, 
    [InAttribute] int lMajorVer, 
    [InAttribute] int lMinorVer, 
    [InAttribute] int lLocaleId, 
    [InAttribute] String^ bstrWrapperTool
)
abstract AddActiveX : 
        bstrTypeLibGuid:string * 
        lMajorVer:int * 
        lMinorVer:int * 
        lLocaleId:int * 
        bstrWrapperTool:string -> Reference
function AddActiveX(
    bstrTypeLibGuid : String, 
    lMajorVer : int, 
    lMinorVer : int, 
    lLocaleId : int, 
    bstrWrapperTool : String
) : Reference

Parameters

  • bstrTypeLibGuid
    Type: String

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

  • lMajorVer
    Type: Int32

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

  • lMinorVer
    Type: Int32

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

  • lLocaleId
    Type: Int32

    Optional locale id. For more information, see LocaleID.

  • bstrWrapperTool
    Type: 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.

Return Value

Type: VSLangProj.Reference
Returns a Reference object for the requested ActiveX library object.

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).

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

.NET Framework Security

See Also

Reference

References Interface

VSLangProj Namespace