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
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<java.lang.String> strUnitInfo,
@Optional @DefaultValue("") java.lang.String strStationName,
@Optional @DefaultValue("") java.lang.String strUserID);
The instance:
Holder<String> holder = new Holder<String>("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)
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.
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)
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.
Can anybody help?
EDIT The instance is create using this UUID:
public static DLL._Tester createTester() {
return COM4J.createInstance( DLL._Tester.class, "{4B7CF2DB-F936-4BA3-9DC6-5E99E5220270}" );
}
Hi i have faced the same issue one month back and the final resolution i have founded which has resolved my issue is changing my java 64bit to 32 bit, and it started working. note- only add com4j.jar in build path and do not register any .dll files.
Hope this will work for you
CoCreateInstance failed : Class not registered
means the GUID you provided does not match any COM item in your Windows registry.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
).To register your DLL, maybe How do I register a DLL file on Windows 7 64-bit? helps.
EDIT Check your registry under
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID
. Is you GUID listed under Classes?