Using Return Value of the Script Callback
To use the return value of the JScript Function we need to pass parameter VARIANT *pVarResult to the Invoke Method of the IDispatch.
Lets implement an adder that takes one integer as parameter and return the result as paramter + 1.
function adder(a)
{
alert("a = " + a);
return a + 1;
}
We have already seen how to pass a parameter using dispParams to JScript Function. Now we just need to define result variant to store the result and then invoke the Invoke on the dispatch.
VARIANT result;
Call to the invoke
m_disp->Invoke(
DISPID_VALUE,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
&dispParams,
&result,
NULL,
NULL);
Attached code contains the complete adder code.
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