根据应用程序运行的位数加载 32 位或 64 位并行 COM DLL
我有一个使用 COM DLL 的 .NET 应用程序,其中有 32 位和 64 位版本。我编写了两个应用程序清单,使并行 COM 互操作可以在 32 位或 64 位上工作。这里是 32 位版本:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="MyApp" version="1.0.0.0" type="win32" />
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="MyCOMDll_32.dll"
version="1.2.3.4"
processorArchitecture="x86"
publicKeyToken="0000000000000000"
language="*" />
</dependentAssembly>
</dependency>
</assembly>
但是,维护两个清单会导致可移植性的损失:您需要在安装应用程序时决定使用哪个版本。并且64位应用程序无法再在32位模式下运行。
是否有可能让 .NET 应用程序根据其运行位数加载正确的 32 位或 64 位 DLL? 我尝试使用两个依赖项元素,一个使用 < assemblyIdentity processArchitecture="x86" .../>
,另一个使用 < assemblyIdentity processArchitecture="amd64" .../> ;
,但这会导致应用程序配置错误。
我将非常感谢您的回答。 问候, 莫里茨
I have a .NET application that uses a COM DLL, of which there is both a 32bit and a 64bit version. I have written two application manifests that make side-by-side COM interop work on either 32 Bit or 64 Bit. Here the 32-bit version:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="MyApp" version="1.0.0.0" type="win32" />
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="MyCOMDll_32.dll"
version="1.2.3.4"
processorArchitecture="x86"
publicKeyToken="0000000000000000"
language="*" />
</dependentAssembly>
</dependency>
</assembly>
However, maintaining two manifests leads to the loss of portability: you need to decide which version to use when you install the application. And the 64-bit application can no longer be run in 32-bit mode.
Is there a possibility to get the .NET application to load the correct 32-bit or 64-bit DLL depending on the bitness under which it runs?
I have tried using two dependency elements, one with <assemblyIdentity processorArchitecture="x86" .../>
and one with <assemblyIdentity processorArchitecture="amd64" .../>
, but that results in an application configuration error.
I'd be very grateful for answers.
Regards,
Moritz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有找到使用应用程序清单来执行此操作的方法。因此,我放弃了应用程序清单,转而采用使用激活上下文 API 的编程解决方案。
此解决方案改编自 http://support.microsoft.com/kb/830033/ en-us (其中字段 cookie 必须是 IntPtr 而不是 uint)。
我已将 EnsureActivationContextCreated() 方法的内部部分替换为
I have not found a way to do this with an application manifest.Therefore, I dropped the application manifest in favor of a programmatic solution using the Activation context API.
This solution has been adapted from http://support.microsoft.com/kb/830033/en-us (where the field cookie must be an IntPtr not a uint).
I have replaced the inner part of the EnsureActivationContextCreated() method by