8

Hi I am currently task to convert a legacy Visual Basic 6 Application that communicates with the a Passbook Printer via third Party Application XFS.ocx (No source).

Based on my research I could JACOB to do this task but I am encountering an error. Can anyone help me? Based on the logs my program can instantiate the activeXcomponent and see the id of the methods I want to use however when I try to use them I encounter an error.

In the sample VB6 code I am using as a guide the method VersionRequired requires two integers as a parameter while ApplicationID requires just a string.

Hopefully I just made a mistake on the syntax or JACOB method to use as I only want to use java JNI as a last resort. Please note this application will always be installed in a Windows(7/10) workstation so other OS compatibility is not an issue.

Here is my Code

ActiveXComponent activeXComponent = new ActiveXComponent("XFS.XFSCtrl.1");


System.out.println( activeXComponent.getIDOfName(activeXComponent, "ApplicationID"));
System.out.println( activeXComponent.getIDOfName(activeXComponent, "VersionRequired")); 
System.out.println( activeXComponent.getIDOfName(activeXComponent, "Description"));
System.out.println( activeXComponent.getIDOfName(activeXComponent, "Open"));

//Variant variant = activeXComponent.call(activeXComponent, "VersionRequired",1,1);
//Variant variant = activeXComponent.call(activeXComponent, "Description"); // added 072318 for David answer
//Variant variant = activeXComponent.getProperty("Description");
//activeXComponent.setProperty("Description", "Description");
//Variant variant = activeXComponent.get(activeXComponent,"Description");
activeXComponent.call(activeXComponent, "Description", "value");

Here is the logs and error I am encountering

WARNING: JNI local refs: zu, exceeds capacity: zu
    at java.lang.System.initProperties(Native Method)
    at java.lang.System.initializeSystemClass(System.java:1166)
main: Loading library jacob-1.19-x86 using System.loadLibrary 
main: Loading library jacob-1.19-x86 using System.loadLibrary 
main: Loading library jacob-1.19-x86 using System.loadLibrary 
main: ComThread: before Init: 0
main: ComThread: after Init: 0
main: ROT: Automatic GC flag == false
main: ComThread: after ROT.addThread: 0
main: ROT: adding com.jacob.activeX.ActiveXComponent@11d50c0->com.jacob.activeX.ActiveXComponent table size prior to addition:0
13
31
1
21
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:1
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:2
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:3
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:4
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:5
Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Description
Description: 8000ffff / Catastrophic failure

    at com.jacob.com.Dispatch.invokev(Native Method)
    at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
    at com.jacob.com.Dispatch.callN(Dispatch.java:453)
    // at com.jacob.com.Dispatch.get(Dispatch.java:788) // added 072318 when using activeXComponent.get(activeXComponent,"Description")
    at com.jacob.com.Dispatch.call(Dispatch.java:541)
    // at com.jacob.com.Dispatch.call(Dispatch.java:529) // added 072318 for David answer
    at ph.com.bdo.icos.passbook.Launcher.main(Launcher.java:32)

VB Code I am Using as a reference

  With XFS1
        'Set up the versions required of XFS and SP
        .VersionRequired(WFS_VERSREQ_OLE, WFS_VERSREQ_LOW) = 1#   ' 2.00
        .VersionRequired(WFS_VERSREQ_OLE, WFS_VERSREQ_HIGH) = 2#  ' 2.00
        .VersionRequired(WFS_VERSREQ_API, WFS_VERSREQ_LOW) = 1.01
        .VersionRequired(WFS_VERSREQ_API, WFS_VERSREQ_HIGH) = 2#
        .VersionRequired(WFS_VERSREQ_SRV, WFS_VERSREQ_LOW) = 1.01
        .VersionRequired(WFS_VERSREQ_SRV, WFS_VERSREQ_HIGH) = 2.1
        'Get back one of the values for testing
        fResult = .VersionRequired(WFS_VERSREQ_API, WFS_VERSREQ_LOW)

        'Set and Get the Application property for testing
        .ApplicationID = "Passbook Printer"
        sAppID = .ApplicationID
        sDescription = .Description
Jefrey Valencia
  • 713
  • 3
  • 13
  • 30
  • 1
    Which jdk are you using (oracle/openjdk/...) – Javier Toja Jul 16 '18 at 09:30
  • 2
    Also on the vb6 code your are not initializing .Description, is this some kind of global var or something?. The stactrace are showing this: *Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Description* – Javier Toja Jul 16 '18 at 09:35
  • Hi karelss 1) Oracle - jdk1.8.0_172 2) In the VB code I am using as a reference its a local variable and was not initialized before it was used but it was not throwing an error. In my code I was just trying to show that I think (might be wrong) that I was able to initialize the target .OCX as I was able to get the method ID's. However when I try to use any of the methods show I am encountering the same "8000ffff / Catastrophic failure" – Jefrey Valencia Jul 16 '18 at 09:51

1 Answers1

3

My guess is than Description is a read-only property, not a function

so you can't use a call on it and this code will bug, producing a catastrophic failure (COM error have always been obscure):

activeXComponent.call(activeXComponent, "Description", "value");

as explained by the message log :

Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Description

and you can't set a property either because it's read-only:

activeXComponent.setProperty("Description", "Description");

Actually if you read your VB6 code correctly, the Description property is just read

sDescription = XFS1.Description

Try this instead:

Variant v = activeXComponent.call(activeXComponent, "Description"); String description = v.toString();

David Doumèche
  • 508
  • 3
  • 10
  • Hi David! Thanks for your reply. Sorry I already tried that method before but forgot to document it in the question (Updated Now). It produces the same exception just on a different line in the Dispatch.Java class (541 -> 529). – Jefrey Valencia Jul 23 '18 at 02:30
  • 1
    What about this : Dispatch.get(activeXComponent, "Description") ? – David Doumèche Jul 23 '18 at 05:09
  • 1
    also the jvm should be with the same architecture as the OCX, i.e 32bits – David Doumèche Jul 23 '18 at 05:16
  • Hi David! Thanks for the reply. Updated my question with your suggestion still the same exception in a different part of Dispatch.Java. I double check the version using System.getProperty("sun.arch.data.model") and its output is 32. – Jefrey Valencia Jul 23 '18 at 06:11