你好我是雅各布的新手。
我想在我的Java代码中使用第三方ocx。我没有得到如何从我的Java代码调用ocx函数。我试过很多方法,但无法确定正确的方法。
每当我对ocx函数使用call或invoke方法时,它都会给我错误。
The Library been loaded, and an activeX component been created
Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: StartAcquire
Description: An unknown COM error has occured.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.call(Dispatch.java)
at ReadDLL.main(ReadDLL.java:40)
这是我的代码:
private static Object activeXWordObject = null;
public static void main(String[] args){
//Loading the library:
ComThread.InitMTA();
ActiveXComponent comp=new ActiveXComponent("CLSID:{9F368618-C114-401F-823D-CF97415B5D5C}");
//ActiveXComponent comp=new ActiveXComponent("Vt2 Control.Application");
activeXWordObject = comp.getObject();
System.out.println("The Library been loaded, and an activeX component been created");
int arg1=100;
int arg2=50;
Short o2 = 2;
boolean vTrue = true;
// object nu - null;
Short port =4;
//using the functions from the library:
// Dispatch.put(activeXWordObject,"CommPort",port);
//comp.invoke("NewSession", new Variant[] {});
//Dispatch.callSub(activeXWordObject, "NewSession");
//Variant v = Dispatch.invoke("NewSession");
//comp.setProperty("CommPort", 2);
Dispatch.call(activeXWordObject, "StartAcquire");
//Dispatch.call(activeXWordObject, "CommPort",port).toVariantArray();
//Dispatch.call(comp, "NewSession");
//Dispatch.call(activeXWordObject, "PortOpen",vTrue);
// Dispatch.put(comp, "ParaMode",o2);
System.out.println("After New session");
/**The following code is abstract of using the get,
* when the library contains a function that return
* some kind of a struct, and then get its properties and values
**/
// Dispatch disp=Dispatch.call(comp,"sum",100,10).toDispatch();
// DataType Var=Dispatch.get(disp,"Property Name");
}