Compartilhar via


Passing Parameter to the Script Callback

Earlier post talked about how to call a callback script from the COM component. What if one wants to call a function that takes parameter say alerter.

function alerter(b)

{

    alert("b = " + b);

}

Now to call this function we need to use other parameters of Invoke method of IDispatch which we had initialised to default.

DISPPARARMS dispParams that we intialised earlier with default value needs attention here. It takes the variant arguments, and named arguments. JScript does not support named arguments. So we can only use variant arg parameter.

So we define one VARIANTARG with interger value here.

VARIANTARG param;

param.vt = VT_INT;

param.intVal = 10;

And then intialise it in dispParams as

DISPPARAMS dispParams = {

&param, // paramters

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

      1, // no. of parameters

      0 }; // no. of named parameters

That’s it. Calling Invoke now would call the alerter.

m_disp->Invoke(

      DISPID_VALUE,

      IID_NULL,

      LOCALE_USER_DEFAULT,

      DISPATCH_METHOD,

      &dispParams,

      NULL,

      NULL,

      NULL);

Next post we will see how to use return value.

Alerter.zip

Comments

  • Anonymous
    September 25, 2007
    Here are links to a virtual series written by Sheetal, one of the developers in the JScript team on Jscript