0

My environment is Java 8, on Windows 7 - 64 bit. So here's my requirement and procedures I followed java:java version "1.8.0_131" 32 bit jacob:jacob-1.18-x86.dll &jacob.jar

i use the eclipse to run the following code .it works well.

import com.jacob.com.*;
import com.jacob.activeX.*;
public class DispatchTest {
    public static void main(String[] args) {
        ActiveXComponent xl = new ActiveXComponent("Execl.Application");
        Dispatch xlo = (Dispatch)(xl.getObject());
        try {
            System.out.println("version="+xl.getProperty("Version"));
            System.out.println("version="+Dispatch.get(xlo, "Version"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            xl.invoke("Quit", new Variant[] {});
        }
    }
}

when i try to use the third party dll and i meet the following execption:

import com.jacob.com.*;
import com.jacob.activeX.*;
public class DispatchTest {
    public static void main(String[] args) {
        ActiveXComponent xl = new ActiveXComponent("ProjectParser.1");
        Dispatch xlo = (Dispatch)(xl.getObject());
        try {
            System.out.println("version="+xl.getProperty("Version"));
            System.out.println("version="+Dispatch.get(xlo, "Version"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            xl.invoke("Quit", new Variant[] {});
        }
    }
}

Exception in thread "main" com.jacob.com.ComFailException: Can't QI object for IDispatch
    at com.jacob.com.Dispatch.createInstanceNative(Native Method)
    at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
    at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
    at DispatchTest.main(DispatchTest.java:5)

https://github.com/joval/jacob/blob/master/jni/Dispatch.cpp

can anyone please guide me to the solution?

chunguiw
  • 831
  • 9
  • 6

1 Answers1

0

Check you COM object with Oleview.exe tool. I assume that your object doesn't implement IDispatch interface. If you still need to use it, you can try your out Com4J library, which can interact COM Objects without IDispatch interface.

You're gonna need to create java class file for your COM object with tlbimp.jar, which comes with Com4J distribution. See Com4J tutorials for more info.

JackHammer
  • 458
  • 1
  • 3
  • 16