COM – Creating a COM Component using C++ – Registering a COM component

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

@="Hello Component"


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.



Add a Comment

Your email address will not be published.