問題描述
我有以下配置:
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-bit 安裝訪問 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:我嘗試使用 Java 8 64 位安裝訪問 32 位應用程序.我收到一條錯誤消息:
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 上搜索了異常,我做了以下操作:
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).
作為快速入門,您可以將您的 CoClass 標記為默認 dllhost.exe
代理進程的候選者:OLE/COM Object Viewer (x86) as Admin > All Objects > [Your 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!