Hey folks,
I have a proprietary OCX for a clicker system I use in my high school math classroom. The vendor gave me a VB SDK for calling the OCX functions and that works fine. However, I want to write apps using Java. So, I've thought about two options: 1) creating a VB DLL wrapper around the OCX and then calling routines from the VB DLL and 2) calling the routines from Java using some kind of Java COM bridge.
Choice 1 seems like the more difficult choice because I'll still have to use some kind of Java COM bridge to access the VB DLL. Also, if my memory serves me correctly, I recall that VB DLL's are not necessarily accessed the same way that C or C++ DLL's are (or maybe that changed with .NET?).
So, I spent the last week trying to find a Java COM bridge to make contact with the OCX directly. I've read through many posts here and I've searched around the net quite a bit. I've looked at JACOB, com4j, jawin, and comeclipse and I still can't get to the point where I can create a Java. com4j and comeclipse have come the closest to making me feel like there is light at the end of the tunnel. com4j's web site suggested using OLEVIEW to create the .IDL file that is almost like having the the type library (.tlb). That seemed to work, I do have a .IDL file. But when I tried to use com4j to create my wrapper files, the ClassFactory class didn't have any methods defined (it should have had some create... methods).
So, then I tried comeclipse. That actually took the OCX directly and created a number of Java wrapper code files. The answer may actually already be in my hands, but I'm not sure how to instantiate the objects in the wrapper code files. I'm lucky because the OCX file includes a function that produces an About box (sAbout). So, if I can figure out the syntax to call the About box, I should be able to figure out the rest of the syntax.
It would be awesome if someone had a clue about the syntax required in order to pull that About box up from Java.
This is the code from what looks like the main (I guess you could call it the root) file. Furtherdown the page, I have the Java code that includes the sAbout reference.
Filename: ctlPrsX.java (the OCX is called PrsX.ocx)
/*
* Generated on Sun Sep 14 14:43:08 PDT 2008
*
* This class was 100% generated by the SWTtoCOM Type library
* generator. Please do not edit this class manually since
* all changes will be lost on the next generation.
*/
package prsx;
import au.com.swz.swttocom.swt.types.TypeUtils;
import org.eclipse.swt.internal.ole.win32.GUID;
import org.eclipse.swt.internal.ole.win32.IUnknown;
import org.eclipse.swt.ole.win32.OleAutomation;
import prsx.impl.__ctlPrsXListener;
import prsx.impl._ctlPrsXImpl;
public class ctlPrsX extends _ctlPrsXImpl {
public static final GUID CLSID = TypeUtils.IIDFromString("{E08B4F09-B88A-11D3-B5DB-00104BA291B8}");
private IUnknown objIUnknown;
private __ctlPrsXListener mf_ctlPrsXListener;
/**
* Constructs a new ctlPrsX from the specified OleAutomation.
*/
public ctlPrsX(OleAutomation oleAutomation) {
super(oleAutomation);
}
/**
* Constructs a new ctlPrsX from the specified OleAutomation and IUnknown.
*/
public ctlPrsX(OleAutomation oleAutomation, IUnknown unknown) {
super(oleAutomation);
this.objIUnknown = unknown;
}
/**
* Adds the specified listener to the set of Listeners that
* will be notified when events occur.
*
* @param listener the new listener to add.
* @return true if the set of listeners did not already contain
* the specified listener, false otherwise.
*/
public boolean add__ctlPrsXListener(__ctlPrsX listener) {
if (mf_ctlPrsXListener == null) {
mf_ctlPrsXListener = new __ctlPrsXListener();
addEventListener(__ctlPrsX.IID, 1, mf_ctlPrsXListener);
addEventListener(__ctlPrsX.IID, 2, mf_ctlPrsXListener);
addEventListener(__ctlPrsX.IID, 3, mf_ctlPrsXListener);
addEventListener(__ctlPrsX.IID, 4, mf_ctlPrsXListener);
addEventListener(__ctlPrsX.IID, 5, mf_ctlPrsXListener);
addEventListener(__ctlPrsX.IID, 6, mf_ctlPrsXListener);
addEventListener(__ctlPrsX.IID, 7, mf_ctlPrsXListener);
}
return mf_ctlPrsXListener.addListener(listener);
}
/**
* Removes the specified listener from the set of Listeners that
* will be notified when events occur.
*
* @param listener the listener to remove.
* @return true if the set of listeners contained the specified
* listener, false otherwise.
*/
public boolean remove__ctlPrsXListener(__ctlPrsX listener) {
boolean bRtn = mf_ctlPrsXListener.removeListener(listener);
if (mf_ctlPrsXListener.isEmpty()) {
removeEventListener(__ctlPrsX.IID, 1, mf_ctlPrsXListener);
removeEventListener(__ctlPrsX.IID, 2, mf_ctlPrsXListener);
removeEventListener(__ctlPrsX.IID, 3, mf_ctlPrsXListener);
removeEventListener(__ctlPrsX.IID, 4, mf_ctlPrsXListener);
removeEventListener(__ctlPrsX.IID, 5, mf_ctlPrsXListener);
removeEventListener(__ctlPrsX.IID, 6, mf_ctlPrsXListener);
removeEventListener(__ctlPrsX.IID, 7, mf_ctlPrsXListener);
mf_ctlPrsXListener = null;
}
return bRtn;
}
}
Filename: _ctlPrsX.java (this file includes sAbout reference)
/*
* Generated on Sun Sep 14 14:43:08 PDT 2008
*
* This class was 100% generated by the SWTtoCOM Type library
* generator. Please do not edit this class manually since
* all changes will be lost on the next generation.
*/
package prsx;
import au.com.swz.swttocom.swt.types.IAutomationObject;
import au.com.swz.swttocom.swt.types.TypeUtils;
import au.com.swz.swttocom.swt.types.pointer.IntPointer;
import au.com.swz.swttocom.swt.types.pointer.StringPointer;
import au.com.swz.swttocom.swt.types.pointer.VariantPointer;
import org.eclipse.swt.internal.ole.win32.GUID;
import org.eclipse.swt.ole.win32.Variant;
public interface _ctlPrsX extends IAutomationObject {
static GUID IID = TypeUtils.IIDFromString("{4F0E0D87-ABE3-4B53-A25F-BCD5CD8F4CC7}");
public String sAbout();
public void unInit();
public String sDecode(StringPointer sCID, VariantPointer bBuf);
public String sInit(IntPointer iCom);
public boolean rFInit();
public boolean rFStartClass(StringPointer className);
public boolean rFStartClassSP(StringPointer className);
public boolean rFStartQt(StringPointer correctAnswer);
public boolean rFStartQtHW();
public boolean rFStartQtSP();
public boolean rFStopQuestion();
public boolean rFStopClass();
/**
* Constructs a Variant representation of this interface that can then
* be used to pass this interface as a parameter to methods.
*
*@return a Variant representation of this interface.
*/
public Variant createSWTVariant();
}