Skip to content

Isolated COM - Sample for registration free COM

License

Notifications You must be signed in to change notification settings

vbcodec/isolated_com

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Isolated COM - Registration-Free COM Sample

This is a sample to demonstrate how to call a COM library written in .NET from a C++ client without doing any of the COM related registration steps.

The COM library is a base64 Encoder/Decoder albeit it's named Decoder.

To compile and build the C++ client, you need to provide the COM library's tlb file. The tlb file can be generated using the following command:

tlbexp.exe decoder.dll

The trick to get the C++ client to "see" the COM library is to have the correct manifests in place for both client and library.

Generating the manifest for the Decoder library is done using the tool mt.exe shipped with Visual Studio.

mt -managedassemblyname:decoder.dll -out:decoder.manifest -nodependency

This will generate a manifest that looks something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"manifestVersion="1.0">
    <assemblyIdentity name="Decoder" version="1.0.0.0" processorArchitecture="msil">
    </assemblyIdentity>
    <clrClass clsid="{6477C617-F645-3313-9F41-CC5112BEDEA5}" progid="Decoder.StringDecoder" threadingModel="Both" name="Decoder.StringDecoder" runtimeVersion="v4.0.30319">
    </clrClass>
    <file name="decoder.dll" hashalg="SHA1"></file>
</assembly>

The C++ client's manifest file can be either written by manually, or using Visual Studio's

project configuration properties > Linker > Manifest File > Additional Manifest Dependencies

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        type = "win32"
        name = "Win32ConsoleApplication"
        version = "1.0.0.0" />
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                processorArchitecture="msil" 
                name="Decoder"
                verrsion="1.0.0.0" />
        </dependentAssembly>
    </dependency>
</assembly>

Using the mt.exe tool, you can also embed each manifest in its corresponding exe or dll to reduce the number of files deployed.

mt -manifest client.exe.manifest -outputresource:client.exe;#1
mt -manifest decoder.manifest -outputresource:decoder.dll;#1

About

Isolated COM - Sample for registration free COM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 76.9%
  • C++ 23.1%