从 x64 .NET 访问 x86 COM [英] Access x86 COM from x64 .NET

查看:33
本文介绍了从 x64 .NET 访问 x86 COM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 x64 服务器,因为我的库被编译为 AnyCPU,所以在 x64 下运行.我们需要访问在 x86 下注册的 COM 组件.我对 COM 知之甚少,而且我的谷歌搜索无处可去.

I have an x64 server which, since my libraries are compiled to AnyCPU, run under x64. We are needing to access a COM component which is registered under x86. I don't know enough about COM and my google searches are leading me nowhere.

问题:对于 COM 组件,我可以使用从 x64 返回到 x86 的符号注册表链接吗?我是否也需要在 x64 下注册 COM 组件?我可以(这里有任何声明...)吗?

Question: Can I use a symbolic registry link from x64 back to x86 for the COM component? Do I need to register the COM component under x64 as well? Can I (any statement here...) ?

谢谢.

推荐答案

如果组件正在运行 x64-native,则它无法在进程中加载​​ 32 位 COM 服务器,因为这是错误的进程类型.有几种可能的解决方案:

If a component is running x64-native, it can't load a 32-bit COM server in-process, because it's the wrong sort of process. There are a couple of solutions possible:

  1. 如果可以的话,构建一个 64 位版本的 COM 代码(当然会在 64 位注册表中注册自己).这是最干净的解决方案,但如果您没有 COM 服务器的代码,则可能无法实现.

  1. If you can, build a 64-bit version of the COM code (which would of course register itself in the 64-bit registry). This is the cleanest solution, but may not be possible if you don't have the code for the COM server.

将您的 .NET 组件作为 32 位 x86 而不是 x64 运行.我想你已经考虑过并出于某种原因拒绝了这个.

Run your .NET component as 32-bit x86, instead of x64. I assume you've already considered and rejected this one for some reason.

使用 COM 代理 DLLhost.exe.这将使对 COM 服务器的调用慢得多(它们现在将是进程间 Windows 消息而不是本机函数调用),但在其他方面是透明的(您不必做任何特殊的事情).

Host the COM component out-of-process using the COM surrogate DLLhost.exe. This will make calls to the COM server much, much slower (they will now be interprocess Windows messages instead of native function calls), but is otherwise transparent (you don't have to do anything special).

如果服务器需要自定义代理存根而不是使用普通的 oleaut32 代理存根(尽管非常罕见),这可能不是一个选项,因为不会有 64 位版本的代理可用.只要能使用普通的OLE编组,就可以注册它以进行代理激活.

This probably won't be an option if the server requires a custom proxy-stub instead of using the normal oleaut32 one (very rare, though), since there won't be a 64-bit version of the proxy available. As long as it can use the ordinary OLE marshalling, you can just register it for surrogate activation.

这篇关于从 x64 .NET 访问 x86 COM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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