views:

258

answers:

1

I'm trying to use JACOB to interact with a COM object.

I was able to invoke an initialization method on the object (and to get its properties), but am not getting any events back. The code is quoted below.
I have a sample HTML+Javascript page (running in IE) that successfully receives events from the same object.
I'm considering the following options, but would appreciate any concrete troubleshooting ideas ...

  • Send my Java program to the team who developed the COM object, and have them look for anything suspicious on their side (does the object have a way on knowing whether there's a client listening to its events, and whether they were successfully delivered?)

  • Get into the native parts of JACOB and try to debug on that side. That's a little scary given that my C++ is rusty and that I've never programmed for Windows.

public static void main(String[] args) {
    try {
        ActiveXComponent c = new ActiveXComponent(
                              "CLSID:{********-****-****-****-************}"); // My object's clsid
        if (c != null) {
            System.out.println("Version:"+c.getProperty("Version"));
            InvocationProxy proxy = new InvocationProxy() {                 
                @Override
                public Variant invoke(String methodName, Variant[] targetParameters) {
                    System.out.println("*** Event ***: " + methodName);
                    return null;
                }
            };
            DispatchEvents de = new DispatchEvents((Dispatch) c.getObject(), proxy);
            c.invoke("Init", new Variant[] {
                    new Variant(10), //param1
                    new Variant(2), //param2
                     });
            System.out.println("Wating for events ...");
            Thread.sleep(60000); // 60 seconds is long enough
            System.out.println("Cleaning up ...");
            c.safeRelease();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        ComThread.Release();
    }
}
+1  A: 

Here's the solution to my specific problem:

It turned out that the COM object was written as an invisible ActiveX control that assumes it's running in the context of a window. This was "discovered" by the development team of the component after I gave them the JACOB-based program.

Providing the window context is something that JACOB doesn't seem to do.

The solution in our case will be to get rid of COM (and use JNA to directly call C functions in the native DLL).

Youval Bronicki