简体   繁体   English

使用本机/托管环境将无注册COM清单嵌入到C#dll中

[英]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: 下图说明了这一点:

COM

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.

相关问题 64位COM dll和C#/。Net应用程序之间的免注册互操作 - Registration-free Interop between a 64-bit COM dll and a C#/.Net application 免注册的COM和DLL位置 - Registration-free COM and DLL location 如何从 C++ 非托管/本机 DLL 中的免注册 COM C# 托管 DLL 创建 COM 对象 - How to create a COM object from registration free COM C# managed DLL in a C++ unmanaged/native DLL Dll位于单独文件夹中时免注册COM - Registration-free COM When Dll Located in Separate Folder 从.Net COM dll回拨到Delphi客户端,无需注册(并排)COM - Callback from .Net COM dll to Delphi client in registration-free (side-by-side) COM C#dll上免费注册的COM,VBScript扼流圈 - Registration free COM, VBScript chokes on C# dll c#dll和vc ++ dll内部的COM dll免费注册激活有何不同? - How Registration free activation of COM dll is different inside c# dll and vc++ dll? 使用托管应用程序中的本机注册免费C ++ COM服务器 - Using native registration free C++ COM server from managed app 免注册的类COM互操作和线程 - Registration-free COM-like interop and threading 免注册COM互操作:在终结器中停用激活上下文将引发SEHException - Registration-Free COM Interop: Deactivating activation context in finalizer throws SEHException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM