[英]Embed a Registration-Free COM manifest into a C# dll with native/managed environment
I'm currently working on a mixed native / managed application chain, which employs registration-free COM. 我目前正在开发一个混合的本机/托管应用程序链,它使用免注册COM。 The following image illustrates this:
下图说明了这一点:
The C# wrapper DLL has been created using the tlbimp.exe utility. 使用tlbimp.exe实用程序创建了C#包装器DLL。 This allows each of the C# executables to access the native types and methods in the COM DLL.
这允许每个C#可执行文件访问COM DLL中的本机类型和方法。 The COM DLL itself employs a server based RegFree COM manifest.
COM DLL本身使用基于服务器的RegFree COM清单。
Everything works fine, when the client based RegFree COM manifests are embedded in the C# executables. 当基于客户端的RegFree COM清单嵌入在C#可执行文件中时,一切正常。 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.
但是,我想将这些清单文件移动并统一到C#DLL中,这样可以显着简化版本信息的维护和同步。
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). 由于Visual Studio不提供将清单文件嵌入C#类库的选项,因此我尝试使用清单工具(mt.exe)提取,修改和重新嵌入DLL的默认清单。 This seems to have worked, as the C# DLL now exposes the following manifest, when being queried with mt:
这似乎有效,因为当用mt查询时,C#DLL现在暴露了以下清单:
<?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. 但是,可执行文件拒绝工作,每个人抱怨COM类工厂无法找到丢失的COM模块。
Is there something I have overlooked here? 我在这里忽略了什么吗? Thanks.
谢谢。
I got it working by pinvoking the appropriate Activation Context functions. 我通过调整适当的激活上下文函数来实现它。 Thanks to Hans Passant for the hint.
感谢Hans Passant的暗示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.