使用 Java/JaCoB 让 32 位 COM 客户端与进程外 64 位服务器对话

发布于 2024-10-11 17:20:51 字数 1603 浏览 3 评论 0原文

这个问题表明32位是可能的COM 客户端与 64 位 COM 服务器对话(反之亦然),前提是服务器处于进程外。我正在尝试使用 Java Com Bridge (JaCoB) 库实现一个客户端,以这种方式与第三方进程外服务器通信,根据 这个问题。如果我匹配进程架构(32 位到 32 位或 64 位到 64 位),我使用的测试代码会成功,但对于任何交叉组合都会失败,但有以下例外:

Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Execute
Description: Invalid callee.

    at com.jacob.com.Dispatch.invokev(Native Method)
    at com.jacob.com.Dispatch.invokev(Dispatch.java:858)
    at com.jacob.com.Dispatch.callN(Dispatch.java:455)
    at com.jacob.com.Dispatch.call(Dispatch.java:544)
    at com.jacob.activeX.ActiveXComponent.invoke(ActiveXComponent.java:447)
    ...

有什么想法吗?


更新

调试异常后,我相当确定底层 COM 错误是 DISP_E_BADCALLEE。经过一番网络挖掘后,我发现可能的原因是方法签名无效,因此这里有一些更多详细信息。 COM 服务器是 MATLAB,我尝试调用 Execute 和 Quit 方法。以下是它们的 COM 类型签名(来自 OLEView):

BSTR _stdcall 执行([in] BSTR 名称);
void _stdcall 退出();

这是我的测试代码:

public static void main(String[] args) {
    ActiveXComponent ml = new ActiveXComponent("Matlab.Application.Single.7");
    System.out.println(ml.invoke("Execute","version"));
    ml.invoke("Quit");
    ml.safeRelease();
}

This question indicates that it is possible for a 32-bit COM client to talk to a 64-bit COM server (and vice-versa), provided the server is out-of-process. I'm trying to implement a client using the Java Com Bridge (JaCoB) library to talk to a third-party out-of-process server in this manner, which should be possible according to this question. The test code I'm using succeeds if I match the process architectures (32-bit to 32-bit or 64-bit to 64-bit), but fails for any cross combination with this exception:

Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Execute
Description: Invalid callee.

    at com.jacob.com.Dispatch.invokev(Native Method)
    at com.jacob.com.Dispatch.invokev(Dispatch.java:858)
    at com.jacob.com.Dispatch.callN(Dispatch.java:455)
    at com.jacob.com.Dispatch.call(Dispatch.java:544)
    at com.jacob.activeX.ActiveXComponent.invoke(ActiveXComponent.java:447)
    ...

Any ideas?


Update

After debugging the exception I'm fairly certain the underlying COM error is DISP_E_BADCALLEE. After some web digging I discovered a possible cause is an invalid method signature, so here are some more details. The COM server is MATLAB, and I am trying to call the Execute and Quit methods. Here are their COM type signatures (from OLEView):

BSTR _stdcall Execute([in] BSTR Name);
void _stdcall Quit();

And here is my test code:

public static void main(String[] args) {
    ActiveXComponent ml = new ActiveXComponent("Matlab.Application.Single.7");
    System.out.println(ml.invoke("Execute","version"));
    ml.invoke("Quit");
    ml.safeRelease();
}

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

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

发布评论

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

评论(1

耶耶耶 2024-10-18 17:20:51

在我们的应用程序中,我们当前使用 Com4J 进行 COM 控件访问,但我们注意到某些 ActiveX 控件的调度功能实现得很差(如果我理解正确的话),因此我们必须为每个控件选择是否使用:

  • Com4J 直接访问
  • 它VB6 Wrapper 到 COM 控件,其中引用了 COM 控件,但是我们必须公开我们调用的方法的包装器,并从 Com4J

或 OLE 嵌入

  • SWT COM Brigde 中调用这些方法。

我以前和Jacob一起工作过,但它似乎很不稳定(至少对于我前段时间尝试过的ActiveX控件来说)。

In our application we currently use Com4J for COM Control Access, but we noticed that some ActiveX controls have poorly implemented dispatch functions (if I understood this correctly), so we have to choose for each control if we use:

  • Com4J to access it directly
  • A VB6 Wrapper to the COM control, in which the COM control is referenced, but we have to expose wrappers for the methods we call, and call those from Com4J

or, for OLE embedding

  • The SWT COM Brigde.

I worked with Jacob before, but it seemed to be very unstable (at least for the ActiveX controls I tried some time ago).

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