Search code examples
interfacecomvb6class-library

Seeing functions available when referencing a COM library (created in VS2013) in VB6


I created a Class Library in VS2013 and added a COM Class to it and added some functions. I compiled and brought it to another computer with VB6 so it can be registered and then referenced (.tlb).

As of now I am using CreateObject to call the functions in my COM library like this:

Dim comObj As Object
comObj = CreateObject("comLibrary.test")
Console.WriteLine(comObj.AddNumbers(5,5))

Is there any chance I can see the available functions in my comObj in intellisense. I thought I would be able to through the interface which is called _test and created automatically I think when using Microsoft's COM class.


Solution

  •   Dim comObj As Object
    

    You are using late binding by using CreateObject(). The VB6 IDE has no idea what kind of object might be created at runtime and what its members look like. So it cannot display any IntelliSense info.

    Use early binding instead, the common choice in a VB6 program:

      Dim comObj As New Test
    

    Which requires adding a reference to the .tlb file for the .NET project, the type library. Which tells the VB6 IDE about the type name and the names of its members. You may have to tweak the attributes on your [ComVisible] .NET class so it supports early binding, only necessary if you didn't write the interface explicitly. You use [ClassInterface(ClassInterfaceType.AutoDual)]. Do favor declaring the interface.