本文介绍了无法执行COM类:com4j.ComException:80040154 CoCreateInstance失败:未注册类:.\ com4j.cpp:153的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试几天,以从JAVA应用程序执行".dll"文件.如果您有兴趣,可以阅读我的第一个问题:使用command调用.dll函数线
I'm trying for some days to execute a ".dll" file from an JAVA application. If you are interested you can read my first question: Call a .dll function using command line
我使用"com4j"为我的DLL创建COM类.生成的类看起来不错,我尝试执行代码,更确切地说是执行位于名为"_Tester"的类中的名为"getUnitInfo"的方法:
I used "com4j" to create the COM classes for my DLL. The generated classes looks good and I tried to execute the code, more exactly a method called "getUnitInfo" located in a class called "_Tester":
@DISPID(1610809376) //= 0x60030020. The runtime will prefer the VTID if present
@VTID(8)
int getUnitInfo(
java.lang.String strRequest,
Holder strUnitInfo,
@Optional @DefaultValue("") java.lang.String strStationName,
@Optional @DefaultValue("") java.lang.String strUserID);
实例:
Holder holder = new Holder("test");
_Tester instance = ClassFactory.createTester();
instance.getUnitInfo("", holder, "", "");
但是它抛出了这个异常:
But it throws this exception:
Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
at com4j.ComThread.execute(ComThread.java:203)
at com4j.Task.execute(Task.java:25)
at com4j.COM4J.createInstance(COM4J.java:97)
at com4j.COM4J.createInstance(COM4J.java:72)
at DLL.ClassFactory.createTester(ClassFactory.java:21)
at proiect.DllTest.run(DllTest.java:17)
at proiect.DllTest.main(DllTest.java:11)
我已经在互联网上阅读了很多有关此问题的帖子,但没有任何帮助.使用"PE解构"工具发现我需要执行的.dll文件是基于32位的.我有一个64位的Windows操作系统,但我安装了一个32位的JAVA和Eclipse.
I have read a lot of posts regarding this problem on the internet but nothing helped.Using "PE deconstruct" tool to find out that the .dll file that I need to execute is 32 bit based. I have a 64 bit Windows OS but I installed a 32 bit JAVA and Eclipse.
如果我在命令行中执行"java -version":
If I execute "java -version" o the command line:
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) Client VM (build 25.171-b11, mixed mode)
com4j文档缺少信息,我认为新生成的JAva代码仍需要与旧DLL进行通信,但是我不知道该如何引用它.
The com4j documentation is lacking information, I think the new generated JAva code still need to communicate with the old DLL but I don't know how it has to be referenced.
有人可以帮忙吗?
编辑实例是使用以下UUID创建的:
EDITThe instance is create using this UUID:
public static DLL._Tester createTester() {
return COM4J.createInstance( DLL._Tester.class, "{4B7CF2DB-F936-4BA3-9DC6-5E99E5220270}" );
}
我在Windows注册表中找到了这个:
And I found this in the Windows registry:
推荐答案
CoCreateInstance failed : Class not registered表示您提供的GUID与Windows注册表中的任何COM项都不匹配.
CoCreateInstance failed : Class not registered means the GUID you provided does not match any COM item in your Windows registry.
您可以尝试使用其他GUID加载COM对象-进入系统注册表并找到任何有效的GUID,也许是与Microsoft Excel相关联的GUID(在我的情况下,该条目位于Computer\HKEY_CLASSES_ROOT\Excel.Application\CLSID下).
You can try loading a COM object with a different GUID- go into system registry and find any valid GUID, maybe the one associated with Microsoft Excel (in my case, the entry is located under Computer\HKEY_CLASSES_ROOT\Excel.Application\CLSID).
要注册您的DLL,也许如何在64位Windows 7上注册DLL文件?有帮助.
To register your DLL, maybe How do I register a DLL file on Windows 7 64-bit? helps.
编辑在Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID下检查注册表.您的GUID是否列在类"下?
EDITCheck your registry under Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID.Is you GUID listed under Classes?
这篇关于无法执行COM类:com4j.ComException:80040154 CoCreateInstance失败:未注册类:.\ com4j.cpp:153的文章就介绍到这了,希望我们推荐的答案对大家有所帮助没有注册类80040154没有注册类80040154,也希望大家多多支持IT屋!