Welcome to MSDN Blogs Sign in | Join | Help

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

m_disp->Invoke(

      DISPID_VALUE,

      IID_NULL,

      LOCALE_USER_DEFAULT,

      DISPATCH_METHOD,

      &dispParams,

      NULL,

      NULL,

      NULL);

Published Saturday, August 11, 2007 2:52 AM by Sheetal Kamat
Filed under: , ,

Attachment(s): Sample.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# JScript COM interop...

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

Tuesday, September 25, 2007 12:30 PM by Gaurav Seth's WebLog

# re: Passing more than one parameter to the script callback

Cool topic! ;)

Sunday, December 23, 2007 5:11 PM by Kilkoi

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker