从 .NET COM 客户端连接到 .NET COM 应用程序

发布于 2024-12-06 16:51:28 字数 689 浏览 0 评论 0原文

我遇到了一些本来应该很简单的事情的麻烦。

我正在 .NET 中编写一个 COM 客户端,当编写服务器代码时,该客户端最终将与旧式 C++ COM 接口进行通信。与此同时,我编写了一个未签名的 WPF .NET 应用程序并实现了相同的接口 - 相同的 IID、不同的 ProgID 和 CLSID - 因此我将拥有一个可以用来测试的工具。理论上,我需要做的就是将引用从一个名称空间切换到另一个名称空间,并更改 new 语句上的具体类,其他所有内容都将保持不变。我设想,当我共同创建 CLSID 时,它将启动带有 GUI 的应用程序,我的客户端可以从那里进行 OLE 自动化风格的调用,并在屏幕上查看效果。

但事实并非如此。在为我的客户端应用程序添加引用中,我在 COM 列表中看到测试工具的类型库,但它拒绝让我添加引用,因为它检测到它是 .NET 类型库并需要 .NET 引用。如果我将它作为项目引用或作为 EXE 浏览到它,它显然会在进程中加载​​ EXE,就好像它是 DLL 一样,并使用 COM 类,而无需在进程外实际激活它。

我认为我使用 .NET COM 应用程序所做的任何事情都将与 C++ COM 应用程序类似地工作。我不确定此时我的选择是什么。我是否面临严格的限制,或者是否存在影响此行为的[属性]? (诚​​然,自从我真正认真地详细地进行 COM 互操作以来,已经有几年了,我有一种不安的感觉,因为这确实很简单,但我已经忘记了。)

Lupestro

I'm having trouble with something that should be brain-dead simple.

I am writing a COM client in .NET that will eventually talk to an old-style C++ COM interface when the server code is written. In the meantime, I've written an unsigned WPF .NET application and implemented the same interface - same IID, different ProgID and CLSID - so I'll have a harness I can test with. In theory, all I will need to do is switch my reference from one namespace to another and change the concrete class on the new statement and everything else will remain the same. I'm envisioning that when I CoCreate the CLSID, it will bring up the application with its GUI and my client can do its calls OLE Automation-style from there and see the effects on the screen.

Only that's not what's happening. In Add References for my client application, I see the typelib for my test harness in the COM list, but it refuses to let me add the reference because it detects that it is a .NET type library and expects a .NET reference. If I reference it as a project or browse to it as an EXE, it apparently loads the EXE in-process as if it were a DLL and uses the COM classes without actually activating it out of process.

I figured anything I did with a .NET COM application would work similarly to a C++ COM application. I'm not sure what my options are at this point. Am I facing a hard limitation or are there [attributes] that affect this behavior? (It has admittedly been a couple of years since I did really seriously detailed COM interop and I have an uneasy feeling that this is something really simple that I've since forgotten.)

Lupestro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知你几分 2024-12-13 16:51:28

听起来您需要的是进程外 COM 对象。您可以创建在 .Net 中实现的 COM+ 对象,然后在进程外实例化它们。 本文介绍了如何执行此操作。

Sounds like what you need is out-of-proc COM object. You can create COM+ objects inplemented in .Net and then instantiate them out-of-proc. This article explains how to do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文