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.