Embed a Registration-Free COM manifest into a C# d

2019-04-10 10:19发布

I'm currently working on a mixed native / managed application chain, which employs registration-free COM. The following image illustrates this:

com

The C# wrapper DLL has been created using the tlbimp.exe utility. This allows each of the C# executables to access the native types and methods in the COM DLL. The COM DLL itself employs a server based RegFree COM manifest.

Everything works fine, when the client based RegFree COM manifests are embedded in the C# executables. However, I would like to move and unify these manifest files into the C# DLL, which would ease maintenance and synchronization of version info significantly.

Because Visual Studio doesn't provide an option to embed a manifest file into a C# class library, I have tried to extract, modify, and re-embed the DLL's default manifest with the manifest tool (mt.exe). This seems to have worked, as the C# DLL now exposes the following manifest, when being queried with mt:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity name="FirstClient" version="1.0.0.0" processorArchitecture="msil"></assemblyIdentity><file name="FirstClient.dll" hashalg="SHA1"></file>
<dependency>
            <dependentAssembly>
                        <assemblyIdentity type="win32" name="atl" version="1.0.0.0"></assemblyIdentity>
            </dependentAssembly>
</dependency>
</assembly> 

However, the executables refuse to work, each one complaining about the COM class factory not being able to find the missing COM module.

Is there something I have overlooked here? Thanks.

1条回答
再贱就再见
2楼-- · 2019-04-10 10:43

I got it working by pinvoking the appropriate Activation Context functions. Thanks to Hans Passant for the hint.

查看更多
登录 后发表回答