开发者

Getting a 32-bit COM client to talk to a out-of-proc 64-bit server using Java/JaCoB

开发者 https://www.devze.com 2023-02-04 12:23 出处:网络
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 J

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 co开发者_StackOverflow社区m.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();
}


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号