Search code examples
javajacobtime-and-attendance

jacob com.jacob.com.ComFailException: Can't map name to dispid: CardNumber[0] git hub ZkemSDK project


i am in project to connect with access control and attendance machine i found this project that connect to same type using java in github but in line that i want to Set CardNumber property i have an exception "com.jacob.com.ComFailException: Can't map name to dispid: CardNumber[0]" can some body give me a hand

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;
    }
}

Solution

  • i found somebody override setProperty to be able to add array in this link setParameter for an array property with JACOB my code was this

    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();
          }
    

    and calling was like this

    this.setProperty(zkem,"CardNumber","0","2599970");
    

    before this line

    Variant vResult = Dispatch.call(zkem,"SetUserInfo",dwMachineNum, dwEnrollNo, dwUserName, dwPassword, dwPrivelage,true);