嵌入一个免注册COM清单为C#DLL与本地/管理环境 [英] Embed a Registration-Free COM manifest into a C# dll with native/managed environment
问题描述
我目前工作的一个混合的本机/托管应用程序链,它采用免注册的COM。下图说明了这一点:
I'm currently working on a mixed native / managed application chain, which employs registration-free COM. The following image illustrates this:
C#的包装DLL已经使用tlbimp.exe是实用程序创建的。这允许每个C#的可执行文件来访问本地类型和方法在COM的DLL。在COM DLL本身采用基于服务器的RegFree 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.
一切工作正常,当基于客户端RegFree COM体现嵌入在C#中的可执行文件。不过,我想移动和统一这些清单文件到C#DLL,这将缓解版本信息显著的维护和同步。
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.
由于Visual Studio不会提供一个选项,以嵌入清单文件转换成一个C#类库,我试图提取,修改和重新嵌入DLL的默认清单与清单工具(mt.exe)。这似乎已经奏效,因为C#DLL现在公开以下清单,当被询问与MT:
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>
不过,可执行拒绝工作,每一个抱怨COM类工厂未能找到丢失的COM组件。
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.
推荐答案
我把它通过pinvoking相应的激活上下文职能工作。由于汉斯帕桑特中的提示。
I got it working by pinvoking the appropriate Activation Context functions. Thanks to Hans Passant for the hint.
这篇关于嵌入一个免注册COM清单为C#DLL与本地/管理环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!