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 at 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 piece of component information into the registry, COM component creators no need to bother about the location of the component; which solves the location transparency issue, one of the goals of COM.

Let’s 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 the 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 the Windows registry, open Windows Explorer and double click on HelloComponent.reg file. The entries will be added to the Windows registry. Be careful while you update the registry. It is always recommended to take a backup of your Windows registry in-store the backup into a 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. The next step is to write a client program and access this component from the client program to test whether our component is working fine or not.

We will discuss the creation of the client applications in our next article.

**

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

2 thoughts on “COM – Creating a COM Component using C++ – Registering a COM component

Leave a Reply

Your email address will not be published.

Scroll to top