1

I try to integrate Java application with Bartender Seagull ActiveX interface using jacob 1.19 library. I have a problem with print method because I do not know how to call this method from jacob. I tried following code:

public void print( String printJobName, Boolean waitForSpoolJobToComplete, Integer timeoutMs )
    {    
     Variant args[] = new Variant[ 4 ];
     args[ 0 ] = new Variant( printJobName );
     args[ 1 ] = new Variant( waitForSpoolJobToComplete );
     args[ 2 ] = new Variant( timeoutMs );
     args[ 3 ] = new Variant();
     args[ 3 ].putNoParam();
     Variant ret = format.invoke( "Print", args );
}

where format is a .com.jacob.activeX.ActiveXComponent instance and I get exception:

A COM exception has been encountered: At Invoke of: Print Description: 80020005 / Type mismatch.

I think that Messages argument causes this exception. How to pass this argument?

Mariusz
  • 1,907
  • 3
  • 24
  • 39
  • **Messages** is a class under **BarTender** `BarTender.Messages`, I am not familiar with **jacob** but little understanding from your code you need to find a way to get **class** `Messages` under `Bartender` – Raynoceros Oct 23 '19 at 03:32
  • Is it possible to use **jacob** retrieve [Messages Object](http://help.seagullscientific.com/2016/en/Subsystems/ActiveX/Content/Message_Object.htm) `BarTender.Messages`? – Raynoceros Oct 23 '19 at 03:38
  • I think that better idea is to retrieve [Messages Collection Object](http://help.seagullscientific.com/2016/en/Subsystems/ActiveX/ActiveX.htm#Messages_collection_.htm). I tried to retrieve it but I failed. I do not know how to do it. – Mariusz Oct 23 '19 at 06:18
  • You have something like `ActiveXComponent comp=ActiveXComponent.createNewInstance("BarTender.Application");` right? Can get **Messages Collection** from `comp`? – Raynoceros Oct 23 '19 at 07:08
  • I have 'ActiveXComponent comp = new ActiveXComponent( "BarTender.Application" );'. It is [Application Object](http://help.seagullscientific.com/2016/en/Subsystems/ActiveX/ActiveX.htm#Application_Object.htm) and I do not know how to get Messages Collection Object from it. I can get/set properties and call methods but there is no any method which returns Messages Object. – Mariusz Oct 23 '19 at 13:31
  • I did a few scan through the [Help Seagull](http://help.seagullscientific.com/2016/en/Subsystems/ActiveX/ActiveX.htm) i found out that **Message Object** and **Messages Collection Object** having different reference. For **Message Object** it is `'BarTender.Message'` and **Messages Collection Object** is `'BarTender.Messages'` – Raynoceros Oct 24 '19 at 02:42
  • Can you try have both **Message** and **Messages Collection** declare? `ActiveXComponent btMsgCol = new ActiveXComponent( "BarTender.Messages" );` `ActiveXComponent btMsg = new ActiveXComponent( "BarTender.Messages" );` Using `btMsgCol` inside `Format.Print` function and have `btMsg` to see each element in `btMsgCol` return by `Format.Print` – Raynoceros Oct 24 '19 at 02:47
  • I will compile all my attempts above into an answer so you can comment on it rather than messing comment section here – Raynoceros Oct 24 '19 at 02:49
  • I wanted to integrate with Bartender 2019. ActiveX is no longer supported in this version. I discovered that Bartender 2019 does not set QueryPrompts correctly. I set QueryPrompts values through ActiveX but these values are not set in SQL queries which database receives from bartender. It works properly in Bartender 2016 so I assume that that my code is correct and Bartender 2019 does not support this functionality. It is one of main functionality for me so I have to change way of integration and abandon ActiveX. – Mariusz Oct 24 '19 at 06:08

1 Answers1

1

Not 100% sure of the code as I didn't try the following code. If any Java errors happens, do correct me.

Did a few reading in Help Seagull:

1. Declare BarTender Variables

ActiveXComponent btApp = new ActiveXComponent( "BarTender.Application" );

2. Prepare Format.Print function

//Format.Print: Returns an object of btPrnRslt
public boolean print( String printJobName, Boolean waitForSpoolJobToComplete, Integer timeoutMs, Variant btMsgCol )
{    
    Variant args[] = new Variant[ 4 ];
    args[ 0 ] = new Variant( printJobName );
    args[ 1 ] = new Variant( waitForSpoolJobToComplete );
    args[ 2 ] = new Variant( timeoutMs );
    args[ 3 ] = new Variant( btMsgCol ); 

    Variant result = format.invoke( "Print", args );

    //if (btPrnRslt <> btPrnRsltSuccess)
    //    return false;
    //else
    //    return true;
}

3. Test Run

if (myFormat.print(firstJob, true, timeOutMS, btMsgCol))
    //Do something if success
else
    //Do something not success
Raynoceros
  • 386
  • 2
  • 15
  • Thank you for help. Code `ActiveXComponent btMsgCol = new ActiveXComponent( "BarTender.Messages" );` throws exception `com.jacob.com.ComFailException: Can't get object clsid from progid`. – Mariusz Oct 24 '19 at 05:54
  • I found [here](https://stackoverflow.com/questions/660319/where-can-i-find-all-of-the-com-objects-that-can-be-created-in-powershell) command which shows all COM objects `gci HKLM:\Software\Classes -ea 0| ? {$_.PSChildName -match '^\w+\.\w+$' -and (gp "$($_.PSPath)\CLSID" -ea 0)} | ft PSChildName`. There is no BarTender.Messages on the list. There are: BarTender.Application, BarTender.Format, BarTender.PreviewHandler, BarTender.PropertyHandler, BarTender.ThumbnailExtension – Mariusz Oct 24 '19 at 05:54
  • I am not know ActiveX/COM well but I think that BarTender.Application is some kind of handler to ActiveX application. I have to use BarTender.Application handler and I can get other handlers from it but I can not create instance of any object when I want. – Mariusz Oct 24 '19 at 05:58
  • Can you try to use `Variant` as BarTender.Messages see if `.invoke` works? – Raynoceros Oct 24 '19 at 07:06
  • `Variant msgCol;` `args[ 3 ] = new Variant( msgCol);` – Raynoceros Oct 24 '19 at 07:07
  • Compilation error: `Error:(454, 34) java: variable msgCol might not have been initialized` – Mariusz Oct 24 '19 at 07:21
  • I found another print function offer by `BarTender.Application.Format`. It is [Format.PrintOut](http://help.seagullscientific.com/2016/en/Subsystems/ActiveX/Content/PrintOut_Method.htm) If you just want to print something i would recommend you try this before we have a solution for `Format.Print` – Raynoceros Oct 24 '19 at 07:22
  • Is there a way to see what is under `BarTender.Application` rather than using [Help Seagull](http://help.seagullscientific.com/2016/en/Subsystems/ActiveX/ActiveX.htm) – Raynoceros Oct 24 '19 at 07:25
  • Format.PrintOut does not throws any exception but nothing happens. Thank you for help. As I wrote in my question's comment I am forced to abandon ActiveX and use some other way Integration Builder or .Net SDK. – Mariusz Oct 24 '19 at 07:46
  • **.NET SDK** is powerful, I am using it. :) You're Welcomed – Raynoceros Oct 24 '19 at 09:37