在 64 位 .NET 应用程序中使用 32 位非托管 COM 服务器
我需要在 64 位 .NET 应用程序中使用 32 位非托管 COM 服务器。
我做了一些研究,似乎找到了一个合适的解决方案:在 COM+ 服务器应用程序中托管 COM 服务器。因此该组件在专用(32 位)进程中激活,并通过 RPC 与 64 位进程进行通信。 (链接)
为了测试上述内容,我创建了一个示例COM 服务器并将其注册到 COM+ 应用程序中。它的界面如下所示:
interface ITestComObj: IUnknown
{
HRESULT _stdcall Ping( void );
HRESULT _stdcall Uppercase([in] LPSTR input, [out, retval] LPSTR * output );
};
然后我创建了一个简单的 .NET 控制台应用程序,该应用程序通过 COM 互操作调用这些方法。
首先我在 32 位 WinXP 上测试了它,它运行得很好。
然后我就换了64位Win7。第一次调用(无参数 Ping() 方法)成功,但第二次调用抛出异常(经过一段等待):远程过程调用失败。 (HRESULT 异常:0x800706BE)。
我做了一些进一步的调查。我强制客户端进入 32 位进程(将其构建到 x86 目标平台)以查看是否有任何变化,但结果是相同的。但是,如果我切换到进程内激活(将 COM+ 应用程序类型更改为库应用程序),客户端就可以工作。
显然,Win7上的跨进程参数传递出了问题,但我在谷歌搜索了几个小时后也找不到答案。
有什么想法吗?
I need to use a 32 bit unmanaged COM server in a 64 bit .NET application.
I did some research and it seemed that I found a suitable solution: hosting the COM server in a COM+ server application. So the component is activated in a dedicated (32 bit) process and it communicates with the 64 bit process via RPC. (link)
To test the above, I created a sample COM server and registered it in a COM+ application. Its interface looks like this:
interface ITestComObj: IUnknown
{
HRESULT _stdcall Ping( void );
HRESULT _stdcall Uppercase([in] LPSTR input, [out, retval] LPSTR * output );
};
Then I created a simple .NET console application that calls these methods via COM interop.
First I tested it on a 32 bit WinXP and it worked fine.
Then I moved to a 64 bit Win7. The first call (to the parameterless Ping() method) was successful, but the second call threw an exception (after some waiting): the remote procedure call failed. (Exception from HRESULT: 0x800706BE).
I did some further investigations. I forced the client into a 32 bit process (built it to x86 target platform) to see if anything changes, but the result was the same. However, if I switched to in-process activiation (changed the COM+ application type to library application), the client worked.
Obviously, something with the cross-process parameter passing is going wrong on Win7, but I couldn't find the answer even after googling for hours.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于编组 - 互操作层出于某种原因无法正确编组第二个调用参数。我建议您更改签名以使用 带有 < 的数组代码>size_is属性。
The problem is with marshalling - the interop layer for whatever reason can't properly marshal the second call parameters. I suggest you change the signature to use arrays with
size_is
attribute.我认为问题可能出在字符串类型的编组上。我会尝试使用:
而不是
I thing the problem could be in the marshalling of string types. I would try using:
instead of