Passing more than one parameter to the script callback

Passing more than one parameter to JScript function isn’t difficult at all after knowing how to pass the parameter. But there is only one trickier part here. I haven’t investigated why this is trickier but it is this way and one must know this other wise the results can be confusing.


Lets say out function foo takes parameter a, b and c and just alerts the values one by one.

function foo(a, b, c)


    alert(“a = “ + a);

    alert(“b = “ + b);

    alert(“c = “ + c);



Now as earlier we need to use dispParams to pass the parameters. But the trickier part here is the order in which the parameters need to be passed. You need to pass in parameters in exactly opposite order as expected. That is the array of parameter arguments should be in order c, b, a.


So we define one VARIANTARG here as :

// Parameters in exactly opposite order.

VARIANTARG param[3];

param[0].vt = VT_INT;

param[0].intVal = 10; // c

param[1].vt = VT_INT;

param[1].intVal = 20; // b

param[2].vt = VT_INT;

param[2].intVal = 30; // a


Then intialise it in dispParams as

DISPPARAMS dispParams = {

      param, // paramters

      NULL, // Named Parameters = JScript doesn’t understand this

      3, // no. of parameters

      0 }; // no. of named parameters


That’s it. Calling Invoke now would call the function with parameters










Comments (2)

  1. Here are links to a virtual series written by Sheetal, one of the developers in the JScript team on Jscript