将无注册COM清单嵌入到具有本机/受管环境的C#DLL中 [英] Embed a Registration-Free COM manifest into a C# dll with native/managed environment

查看:237
本文介绍了将无注册COM清单嵌入到具有本机/受管环境的C#DLL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用混合本机/管理应用程序链,它使用免注册的COM。以下图片说明了这一点:

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

使用tlbimp.exe实用程序创建了C#包装器DLL。这允许每个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#类库中的选项,我已尝试使用清单工具(mt.exe)来提取,修改和重新嵌入DLL的默认清单。这似乎有效,因为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.

推荐答案

我通过引用适当的激活上下文功能来实现它的工作。感谢 Hans Passant 的提示。

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

这篇关于将无注册COM清单嵌入到具有本机/受管环境的C#DLL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆