In our previous article, we have created Type Library “Hello.tlb”. We were facing issues when we tried to add “HelloComponent.dll” as a reference to our Visual Basic test application. Hence we have created “Hello.tlb” Type Library. And we observed that even with “Hello.tlb” Type Library, Visual Basic test application (console based application) is showing error while adding as a reference.
To resolve this, we need to register our “Hello.tlb” Type Library with Windows Registry. Add the following entries into “HelloTypeLib6432.reg” file and run this file from command prompt to add them into Windows Registry. We have added our Type Library information under TypeLib key under GUID of our type library. Location of the type library should be mentioned in win32 key.
Windows Registry Editor Version 5.00
@="HelloComponent Type Library"
@="c:\\Visual Studio Projects 2012\\Hello.tlb"
Now we have registered our Type Library with Windows Registry.
Its time to add our Type Library into Visual Basic test application. Observe that now our type library is successfully added into Visual Basic test application as a reference. Create an instance of our COM component and call its SayHello method. The Visual Basic code would be like below:
Dim obj As New HelloComponentTypeLib.HelloComponent
Call obj.SayHello("Code Steps")
Once you run Visual Basic application, it will display “Hello, CodeSteps” message on console window.
We are successfully called our HelloComponent from Visual Basic application.