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

In our previous article we have packaged a component into a DLL. Now we will look how to register the component.

Registering a COM component means, adding necessary registry entries into Windows Registry. COM library will pick-up the component depending on the added registry entries and create an instance of it. Because of adding a component information into registry, COM component creators no need to bother about the location of the component; which solves location transparency issue, one of the goal of COM.

Lets create a file HelloComponent.reg and place the registry entries within the file. We use the following registry entries:

  • HKEY_CLASSES_ROOT – This key contains file name extension association information and COM class registration information.
  • CLSID – This is the place where we store COM class registration information. This key should be under HKEY_CLASSES_ROOT key.
  • {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} – CLSID of the component. This must be under CLSID key.
  • InprocServer32 – This is the place to provide 32-bit in-proc server and specifies the threading model. This key must be under {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} key.

Once we add this information into HelloComponent.reg file; the file content looks like below:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{23893EE4-8514-4BD6-8830-A7EBDDF5C944}]
@="Hello Component"

[HKEY_CLASSES_ROOT\CLSID\{23893EE4-8514-4BD6-8830-A7EBDDF5C944}\InprocServer32]
@="c:\\HelloComponent\\HelloComponent.dll"

To add these registry entries into Windows registry, open Windows explorer and double click on HelloComponent.reg file. The entries will be added into Windows registry. Be careful while you update the registry. It is always recommended to take backup of your Windows registry in store the backup into safe place. When something went wrong while updating the registry, you can use your backup copy to revert the changes back.

Now HelloComponent is registered. Next step is write a client program and access this component from client program to test whether our component is working fine or not.

We will discuss about creation of client application in our next article.

**

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

  1. abid
    March 30, 2014 at 1:04 PM

    hi, where is the nxt article for creation of client program to test this com component???

    • venkat
      March 30, 2014 at 8:12 PM

      I will post it soon.

      Thanks.

Leave a Reply