使用 Java/JaCoB 让 32 位 COM 客户端与进程外 64 位服务器对话
这个问题表明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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我们的应用程序中,我们当前使用 Com4J 进行 COM 控件访问,但我们注意到某些 ActiveX 控件的调度功能实现得很差(如果我理解正确的话),因此我们必须为每个控件选择是否使用:
或 OLE 嵌入
我以前和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:
or, for OLE embedding
I worked with Jacob before, but it seemed to be very unstable (at least for the ActiveX controls I tried some time ago).