Home > Uncategorized > COM4J updates

COM4J updates

April 27th, 2012

It’s been a while, but I’ve posted a new version of COM4J. COM4J is a library that lets you talk to Windows COM components. Unlike similar libraries lika jacob, which makes you feel like you are working with reflection, COM4J is designed to work with type-safe annotated interfaces, which makes you feel like you are working with Java libraries. COM4J is also built on top of vtable invocation, not on IDispatch, so it can work with components without the dual interface support (boy those words bring back memories!)

I use this library in Jenkins, among other places, to provide a better native integration.

The major change in this version is that it finally has 64bit Java support. The original work was contributed in 2011, but I’ve never cut a release out of it officially. It contains a number of bug fixes, additional conversions support. The code is now on GitHub, and the website is moved to here.

Uncategorized , , ,

  1. Jens
    May 2nd, 2012 at 10:33 | #1

    Great News! Thank you! :)

    Maybe we should post on the “old” com4j java.net mailing list and kinda redirect users from the old project site to your new one?

  2. May 4th, 2012 at 08:13 | #2

    Yes, I should post the release announcement. I still consider that mailing list THE mailing list, as I don’t have anywhere else to host them.

  3. Andras
    May 7th, 2012 at 06:11 | #3

    Hello Kohsuke !
    Sorry to say, but I have problem using com4j. Whenever I try to run tlb import (regardless if I try to run with wshom.ocx or WIA TLB) I got the following error:
    F:\com4j\kohsuke-com4j-b5143ce\tlbimp\lib>java -jar tlbimp.jar -o wia -p wia %WINDIR%\system32\wiaservc.dll
    Exception in thread “main” java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at com4j.ComThread.execute(ComThread.java:220)
    at com4j.Task.execute(Task.java:25)
    at com4j.COM4J.loadTypeLibrary(COM4J.java:322)
    at com4j.tlbimp.driver.Lib.getLibid(Lib.java:90)
    at com4j.tlbimp.driver.Driver.addLib(Driver.java:38)
    at com4j.tlbimp.driver.Main.doMain(Main.java:123)
    at com4j.tlbimp.driver.Main.main(Main.java:56)

  4. AZZANA
    May 18th, 2012 at 17:04 | #4

    wiaaut.dll instead of wiaservc.dll

  5. julien
    June 12th, 2012 at 08:54 | #5

    Hi, I’m currently trying to upgrade à Java solution using ABBY OCR from Windows XP 32bit to Windows 7 64bit. A bridge using com4j exist between the two. Generation of the new interphases works well, but use it or the older generate this stack trace:
    com4j.ComException: 8000ffff Défaillance irrémédiable : Erreur programme interne:
    .\src\RegExpPreprocessor.cpp, 53. : .\invoke.cpp:517
    at com4j.Wrapper.invoke(Wrapper.java:166)
    at $Proxy97.recognizeNextDocument(Unknown Source)
    at net.atos.FraudeDocumentaire.engine.EngineAbbyy.analyseDocument(EngineAbbyy.java:202)
    at net.atos.FraudeDocumentaire.engine.ThreadIdentification.run(ThreadIdentification.java:40)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: com4j.ComException: 8000ffff Défaillance irrémédiable : Erreur programme interne:
    .\src\RegExpPreprocessor.cpp, 53. : .\invoke.cpp:517
    at com4j.Native.invoke(Native Method)
    at com4j.StandardComMethod.invoke(StandardComMethod.java:35)
    at com4j.Wrapper$InvocationThunk.call(Wrapper.java:340)
    at com4j.Task.invoke(Task.java:51)
    at com4j.ComThread.run0(ComThread.java:153)
    at com4j.ComThread.run(ComThread.java:134)

    Have you any idea where problem come from ? Did you think it’s ABBYY internal faillure or com4j?

    Thanks for reading.

  6. steve
    July 13th, 2012 at 11:25 | #6

    can you please provide a simple example of putting an array into an excel range, I’ve tried many things and cannot get this to work….

    Object[][] aSquare = {{“1″,”2″},{“3″,”4″}};

    Range aR = app.getRange(“A1″, Variant.getMissing());
    aR = aR.getResize(2, 2);
    aR.setValue2(aSquare);

  7. Siva Gudur
    August 1st, 2012 at 05:00 | #7

    I am getting the issue with 64 Bit. It obsolutely worked fine for me with 32 Bit. I tried to load the dll explicitly using

    System.load(“D:/com4j-amd64.dll”);

    The dll is loaded successfully but still I am getting

    com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153

    Do any one have any clue? Its greatly appreciated.

  8. Siva Gudur
    August 1st, 2012 at 06:02 | #8

    In detail the error is happening at COM4J.java

    Line 117 : Wrapper.create( intf, Native.createInstance(clsid,clsctx,iid.v[0],iid.v[1]) );

    Hi Kohsuke any insight about this problem is greatly appreciated.

  9. Nilesh
    October 19th, 2012 at 04:18 | #9

    Hello Kohsuke,

    I am getting same error as Siva Gudur, any suggestions to resolve this ?

    Thanks,
    Nilesh

  10. staiger
    December 18th, 2012 at 07:33 | #10

    Hello,
    I tried to run a word macro with one parameter.

    app.application().run(“Modul1.Makro1″,”Norbert”, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);

    but I get the message: “illegal number of parameters.”.

    Thank you

  11. Sathish
    December 24th, 2012 at 01:47 | #11

    Hi,

    I am getting the error for Import statements of word.

    import word.Window;
    import word._Application;
    import word._Document;
    import word.events.ApplicationEvents2;

    Kindly clarify me on the jar files need to be added to Java build path to resolve these import statements error.

    Thanks in Advance!!

    Regards,
    Sathish.

  12. inbaselvan
    January 10th, 2013 at 03:07 | #12

    @Siva Gudur
    Hi Siva,

    any luck? iam having the same problem. Env is Java 7 , win 7 64 bit. your help is highly appreciable.

  13. kams62
    January 18th, 2013 at 07:56 | #13

    @inbaselvan
    Hi inbaselvan,

    Did you find a solution?
    I’m having the same problem.

  14. inbaselvan
    February 5th, 2013 at 02:05 | #14

    @kams62 I was able to fix it by changing my JRE to 32bit instead of 64bit since my dll was a 32bit dll. But now i run into the same problem when i deploy my application with bundled 32bit JRE. Not sure if i did something in addition to changing the JRE to 32 bit.

  15. kaleem786
    February 14th, 2013 at 08:02 | #15

    @kams62 – I am trying to connect HP QC from Java layer. I run into below error
    “com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153 ”

    The above error disappears if I run 32bit JVM but re-occurs if I compile my code using 64bit JVM

    In http://com4j.kohsuke.org/deployment.html page you have mentioned that the latest com4j.jar does handle bot 32bit as well as 64bit, also com4j-x64.jar is included as part of com4j.jar. I don’t see the com4j-x64.jar being bundled.

    Could you please throw some light.

    Thanks for your support.

  16. Rebecca Pridgeon
    April 20th, 2013 at 12:42 | #16

    We are using your package to interface with a com dll from Milliman. One of their methods can return a Double, Float, or a double[]. The Java side return value is an Object but the double[] is not coming back. We get a null instead. I love your product and would like to continue to use it. Can you give us any suggestions on how to proceed? Maybe you could point us to what module needs to be changed. We are great Java programmers but have not programmed in C in years. Thanks for you help.

  17. qvle
    August 13th, 2013 at 15:13 | #17

    Will this com4j.jar file compatible with MAC OSX? .dll on MAC doesn’t make sense, but that is why I am asking this question.

  18. August 13th, 2013 at 21:59 | #18

    COM on OS X makes no sense. COM is a Windows technology.

  19. qvle
    August 14th, 2013 at 08:55 | #19

    Thanks Kohsuke!

  20. Danny
    September 16th, 2013 at 00:14 | #20

    I use com4j on Windows 2008 Server R2. It is a 64bit OS, a 32bit Office and a 64bit JRE are running on it. My problem: My application runs as service under local system account. It has to open a word document by calling wordApp.documents().open(…). The open-method returns null!

    If I run the application by start script everything works fine but not as service. I tried to install Office as 64bit and the service surprisingly works fine, too. What is the problem?

    I suppose the internal selected dll plays a role used by com4j?!

    Best regards Danny

  21. Ankur
    March 26th, 2014 at 06:22 | #21

    @Siva Gudur
    hi Siva,

    how did you solve the problem…please advice

  22. Tamilselvan
    April 2nd, 2014 at 06:48 | #22

    I have a query where my integration with QC is with MAC machine. it was failing constantly with the below exception, even though the libs and everything are referenced to the current project but still it didnt help much,
    [junit] Exception in thread “Com4J shutdown hook” java.lang.NoClassDefFoundError: Could not initialize class com4j.COM4J
    [junit] at com4j.COM4J$3.run(COM4J.java:476)

  23. Monu
    January 13th, 2015 at 10:41 | #23

    error loading type library/dll .\com4j.cpp :395 : getting this error…please help

  24. March 25th, 2015 at 01:31 | #24

    @Monu
    Please resister the OTAClient.dll using regsvr32 command.

  25. suresh
    May 18th, 2015 at 10:37 | #25

    i am getting error like : Exception in the thread “main” com4j,ExecutionException: java.lang.NoClassDefFoundError: office/Assistant . Can somebody help me why am getting that error. Thanks in advance

  26. Fernando Bereta dos Reis
    May 19th, 2015 at 08:46 | #26

    Hello Kohsuke Kawaguchi

    Thank you for these opensource project.
    I’m using it to communicate to OpenDSS (http://sourceforge.net/projects/electricdss/). It works great for most of the commands. But when it’s a vector of real and imaginary values, it generate the following code:
    ///////////////////////////////////////////////////////////////////////////
    /**
    *
    * Complex array of all bus, node voltages from most recent solution
    *
    *
    * Getter method for the COM property “AllBusVolts”
    *
    * @return Returns a value of type java.lang.Object
    */

    @DISPID(11) //= 0xb. The runtime will prefer the VTID if present
    @VTID(17)
    @ReturnValue(type=NativeType.VARIANT)
    java.lang.Object allBusVolts();
    ///////////////////////////////////////////////////////////////////////////
    Unfortunately it doesn’t work, returning null.
    Does anyone knows how to fix these?

  1. No trackbacks yet.