简体   繁体   中英

Jacob: com.jacob.com.ComFailException: Can't co-create object

I am facing exception Exception in thread "main" com.jacob.com.ComFailException: Can't co-create object while running the code below.

I checked online for help. Some sites say that I need to register my dll. I tried registering using regsvr32.exe . But I am unable to register successfully. Getting below popup.

The module "jacob-1.18-M2-x64.dll" was loaded but the entry-point DllRegisterServer was not found.Make sure that "jacob-1.18-M2-x64.dll" is a valid DLL or OCX file and then try again.

1.) You don't need to register the jacob-dll, it just has to be somewhere on your java.library.path. It is the dll that contains the COM-object that has to be registered.

2.) If the COM-dll is registered you have to take care to use the correct JVM with the library. 32-bit-dlls will work only with a 32-bit-JVM, 64-bit-dlls only with a 64-bit-jvm. Using the wrong JVM will result in the Can't co-create object error.

I had the same problem and this is how I fixed it:

  1. Find your COM object using OLE/COM object Viewer
  2. Make sure to register your dll with regsvr32.exe (from C:\\Windows\\System32)
  3. You need to make a surrogate in order to access a 32-bit dll from a 64 bit app. See this here : http://www.gfi.com/blog/32bit-object-64bit-environment/

I encounted same problem and solved like following this. 1.Set lib path of jacob.jar 2.Copy jacob-x86.dll(or 64bit case jacob-x64.dll) to System32 directory.

import com.jacob.activeX.ActiveXComponent;

ActiveXComponent activeXComponent = new ActiveXComponent("ACTIVEX.ActiveXCtrl.1");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM