COM: Creating a COM Component using C++ (Part-13)

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

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{5FD055AD-EE01-4533-97F9-570C97BB0FE1}\1.0]
@="HelloComponent Type Library"

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{5FD055AD-EE01-4533-97F9-570C97BB0FE1}\1.0\0\win32]
@="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:

Module Module1

    Sub Main()
        Dim obj As New HelloComponentTypeLib.HelloComponent

        Call obj.SayHello("Code Steps")
    End Sub

End Module

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.

**

4 comments for “COM: Creating a COM Component using C++ (Part-13)

  1. vishesh
    July 29, 2014 at 9:46 AM

    Hello Venkat, can I get the full source code of both server and client ?

    • venkat
      July 29, 2014 at 12:43 PM

      Hello Vishesh,

      Please follow the series of articles on “COM: Creating a COM Component using C++”.

      Code in-lined in the articles.

      Regards
      Venkat.

      • vishesh
        July 29, 2014 at 3:59 PM

        Hello Venkat,

        I started with visual studio as an empty dll project and was going well until, part 6.
        Dll was created, but an error in client side saying Class not registered.

        It would great if I could get the full source code, so that I can compare my project.

        Thanks in Advance.

        • venkat
          July 30, 2014 at 9:16 AM

          Hello Vishesh,

          The error may be because of incorrect registry entries. I hope you are testing this on “Windows 7” Operating System. As I mentioned in “COM: Creating a COM Component using C++ (Part-6)”, you need to create another set of registry entries. Everything clearly mentioned in the article(s) with complete code.

          Hope this helps.

          Regards,
          Venkat.

Leave a Reply