使用Com4j或Jacob将64位Java与32位COM dll连接 [英] Connect 64bit Java with 32bit COM dll using Com4j or Jacob

查看:955
本文介绍了使用Com4j或Jacob将64位Java与32位COM dll连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下配置:

1)Windows 10 64位

1) Windows 10 64-bit

2)应用程序它只有一个32位版本,可通过COM获得。

2) An application that has only a 32-bit version and is available through COM.

我使用tlbimb.jar访问32位应用程序的.dll文件以生成接口需要和我成功。

I access the .dll file of the 32-bit application using the tlbimb.jar to generate the interfaces needed and I succeed.

场景1:
我尝试使用Java 8 32位访问32位应用程序安装。我可以通过COM 成功调用这些方法,没有任何问题。

Scenario 1: I try to access the 32-bit application using the Java 8 32-bit installation. I can invoke the methods through COM succesfully without any problem.

场景2:
我尝试访问32位应用程序使用Java 8 64位安装。我收到一条错误消息:

Scenario 2: I try to access the 32-bit application using a Java 8 64-bit installation. I get an error message:

Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153

我在Stackoverflow / Google和我搜索了exceptin已完成以下操作:

I searched for the exceptin on Stackoverflow/Google and I have done the following:

1)使用Sys64WOW / regsvr32.exe和System32 / regsvr32.exe注册应用程序的dll

1) Registered the application's dll using both Sys64WOW/regsvr32.exe and the System32/regsvr32.exe

2)使用Sys64WOW / regsvr32.exe和System32 / regsvr32.exe注册com4j dll(32位和64位)

2) Registered the com4j dll (both 32 and 64 bit) using both Sys64WOW/regsvr32.exe and the System32/regsvr32.exe

3)复制Sys64WOW和System32文件夹中的dll。

3) Copied the dlls in the Sys64WOW and System32 folders.

我已完成上述所有操作,检查所有可能的组合。使用64位Java的错误仍然存​​在。

I have done all the above separatelly, checking all the possible combinations. The afortementioned error using 64-bit Java still exists.

我尝试过使用另一个桥(Jacob)。在32位Java上它成功了,在64位Java上失败了。

I have tried using another bridge (Jacob). On 32-bit Java it succeeds, on 64-bit Java it fails.

我有一个问题可能有人知道:有没有办法连接一个应用程序,据我所知,只提供 Win32 COM dll [1],使用任何可用的Java / COM桥和 Java 64bit ?或者只是32位COM + 64位Java无法连接?

I have a question for someone that might knows: Is there any way to connect an app that, as far as I can tell, offers only a Win32 COM dll[1], using any of the available Java/COM bridges and Java 64bit? Or simply 32-bit COM + 64-bit Java are not connectable?

[1]:我检查了OLE / COM查看器,在类型库下面只有一个条目0 Win32 =,所以我暗示这意味着没有Win64 COM dll,对吗?

[1]: I checked the OLE/COM Viewer and under the Type Library there's is only one entry "0 Win32 = , so I implied that this means there's no Win64 COM dll, right?

推荐答案

这不起作用因为客户端进程和COM DLL的位数不匹配。在尝试创建新实例时, CoCreateInstance 尝试在64位配置单元中查找相关的类信息注册表。这失败了,因为它实际上位于您注册DLL的32位配置单元中。

This won't work because the bitness of your client process and COM DLL don't match. When trying to create a new instance, CoCreateInstance tries to find related class information in the 64-bit hive of the registry. This fails because its actually located in the 32-bit hive, where you registered the DLL.

要解决此问题,您可以选择使用代理进程,允许您的CoClass在不同的本机进程中实例化。然后您的客户端可以通过IPC与代理进行通信(参见这里以获取更多信息。)

To remedy this, you have the option of using a surrogate process, which allows your CoClass to be instantiated in a distinct native process. Your client can then communicate with the surrogate via IPC (see here for further info).

As快速入门,您可以将您的CoClass标记为默认 dllhost.exe 代理进程的候选者:OLE / COM对象查看器(x86)为管理员>所有对象> [您的CoClass]>实现>使用代理进程(保留路径为空)。

As a quick start, you can mark your CoClass as a candidate for the default dllhost.exe surrogate process: OLE/COM Object Viewer (x86) as Admin > All Objects > [Your CoClass] > Implementation > Use Surrogate Process (leave path empty).

如果您打算分发您的应用程序,您可以将此信息放在REG脚本中或导入您的DLL进入COM +服务器应用程序。

If you intend to distribute your application, you may place this information in a REG script or import your DLL into a COM+ server application.

这篇关于使用Com4j或Jacob将64位Java与32位COM dll连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆