我在项目中连接门禁和考勤机我在github中发现了这个使用java连接到同一类型的项目但在我想设置CardNumber属性的行中,我有一个例外"com.jacob.com.ComFailException:无法将名称映射到dispid:CardNumber[0]"有人能帮我一把吗
https://github.com/lookskystar/ZKKQProject/blob/master/ZKKQProject/src/com/zkkq/uitl/ZkemSDK.java
public class ZkemSDK
{
private static ActiveXComponent zkem ;
public ZkemSDK(){
zkem = new ActiveXComponent("zkemkeeper.ZKEM.1");
System.out.println("done ");
}
public boolean connect(String address,int port, int machineNum) throws Exception{
boolean result = zkem.invoke("Connect_NET",address,port).getBoolean();
}
public boolean SetUserInfo(int machineNum,int enrollNo2,String userName,String password,int privelage ,boolean flag) {
Variant dwUserName = new Variant(userName,true);
Variant dwPassword = new Variant(password,true);
Variant dwPrivelage = new Variant(privelage,true);
Variant dwEnrollNo = new Variant(enrollNo2,true);
Variant dwMachineNum= new Variant(machineNum,true);
/****/
zkem.setProperty("CardNumber[0]",454545);
/****/
Variant vResult = Dispatch.call(zkem,"SetUserInfo",dwMachineNum, dwEnrollNo, dwUserName, dwPassword, dwPrivelage,true);
return true;
}
}
我发现有人重写了setProperty以便能够添加数组在此链接中具有JACOB的数组属性的setParameter我的代码是这个
public static void setProperty(Dispatch d, String sName, String sIndex, String sValue) {
Variant av[] = { new Variant(sIndex), new Variant(sValue) };
int j[]= {0};
Dispatch.invokev(d, sName, Dispatch.Put, av,j).safeRelease();
av[0].safeRelease(); av[1].safeRelease();
}
呼叫就像这个
this.setProperty(zkem,"CardNumber","0","2599970");
在这条线路之前
Variant vResult = Dispatch.call(zkem,"SetUserInfo",dwMachineNum, dwEnrollNo, dwUserName, dwPassword, dwPrivelage,true);