Question

Am trying to call a function called "set" using COM interface am getting the exception

Exception in thread "main" com.jacob.com.ComFailException: Can't map name to dispid: set

eventhough when I try to call the function in matlab, it's working okey...

this is the function am using

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

}

enter image description here

Was it helpful?

Solution

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

example to use it....

sg_1.setIndexedAttribute("State", new Variant(10));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top