In order to use a Component Object Model (COM) component in an application, the binding/activation information must be made available so that the operating system can find it when a program needs the component. Typically this is accomplished by registering the COM component, which places the activation information in the Windows registry.
Registration-free COM allows a COM component to be activated without registration. This is a feature that has been available since Windows XP.
There are a couple of main advantages to registration-free COM. The first is that it allows us to use XCOPY or FTP to simply copy our application for deployment, without the additional step of registration. Another advantage is that in situations in which you have multiple versions of the same DLL installed on a computer, we can control which version is activated. This reduces the possibility of DLL version conflicts.
Registration-free COM is made possible through the use of manifest files. Component manifest files, which are in XML format and are created at design time, contain the necessary binding and activation details. At runtime, in the absence of registry entries, the manifest files are used for activation.
In order to create a manifest file, we first need the type library (TLB) of the component. A type library is a binary file that stores information about a COM object’s properties and methods, in a form that is accessible to other applications at runtime.
Tools like the Type Library Exporter (Tlbexp.exe) or the Assembly Registration Tool (Regasm.exe) can be used to generate a type library. For cases where you are dealing with an unmanaged COM DLL, you can use a tool such as Resource Hacker.
To generate a type library using Resource Hacker, first open the relevant DLL file and navigate to the TYPELIB node in the treeview.
Right click on the node and select “Save Resource to a *.bin file …”. Supply a filename and give it a .tlb extension.
Now that we have a type library, we can generate a manifest file from it. There are a variety of tools that can be used to generate a manifest file from a type library. One of the most readily available is Mt.exe, which is included in the Microsoft Windows SDK (which is installed with Visual Studio).
At the command line, simply supply the TLB and DLL filenames to mt.exe, along with the name you want used for the output. The output will be the manifest file, so name it with a .manifest extension.
If you open the newly created manifest file, you will see the classes and interfaces exposed by the COM component, along with the binding and activation details that will be needed to use it.
Once the manifest file has been created, use Visual Studio to add the manifest file to the project(s) that will need to use the COM component. In addition, ensure that the COM component DLL is located in the same directory as the assembly that will be using it.
If you want to use a COM component without registering it, using manifest files is a fairly straightforward approach. Taking advantage of this technique will allow you to use XCOPY or FTP for deployment without the additional steps for registration. And if you have a situation in which you have multiple versions of the same COM component on a machine, this approach allows you to control which version will be activated.