尝试使用COM接口调用名为“set”的函数 我得到了例外
Exception in thread "main" com.jacob.com.ComFailException: Can't map name to dispid: set
当我尝试在matlab中调用该函数时,它正在工作......
这是我正在使用的功能
public void setAttribute(String attribute, int value) {
Variant[] vars = new Variant[3];
vars[0] = new Variant("AttValue");
vars[1] = new Variant(attribute);
vars[2] = new Variant(value);
signalGroup.invoke("set", vars);
}
答案 0 :(得分:0)
public void setIndexedAttribute(String attribute, Variant value) {
Variant[] indecies = new Variant[1];
indecies[0] = new Variant(attribute);
setProperty(signalGroup, "AttValue", indecies, value);
}
public void setProperty(Dispatch activex, String attributeName, Variant[] indecies,
Variant value) {
Variant[] variants = new Variant[indecies.length + 1];
for (int i = 0; i < indecies.length; i++) {
variants[i] = indecies[i];
}
variants[variants.length - 1] = value;
Dispatch.invoke(activex, attributeName, Dispatch.Put, variants,new int[variants.length]);
}
使用它的例子......
sg_1.setIndexedAttribute("State", new Variant(10));