Volleynerd Knowledge Base

Friday, October 31, 2003


Outbound parameter from event interface

Want to change parameter in the event handler, and have the caller see the change

Just what we figured out last round for SFP. Script event handlers can not modify a standard ( [in,out] SomeType* val ) parameter.

More info now that I've figured this all out

This article tells that you should make the param type [in,out] VARIANT*, but that actually does not work for JavaScript event handlers (e.g. in a web page). Some people imply that VBScript can handle in,out, but I can't get that to work.

HOWTO: Obtain data from the client via an outgoing event dispinterface in ATL

So...when dealing with JavaScript, change the param type to [out,retval] and then the Fire_xxx code should be looking at the varResult (from ATL generated code) instead of the params passed into the Invoke call.


(find this at groups.google.com with search "out retval parameter event group:microsoft.public.vc.*" )

Update: more info here about using this event from JScript.

Apparently JScript doesn't do [in,out] params, so you have to go with the [out,retval] attributes, and pull the return value out of the 6th param in Invoke.

ATL Wizard code generates mostly correct code (currently using VS 7.1), with zero params (out,retval is not sent in as a param)....but the return value shows up from the 6th param in Invoke. You have to pull this value out of the CComVariant and return it from the Fire_xxx function.

IDL function declaration:

[id(2)] HRESULT OutRetvalVar([out,retval] VARIANT* val);

HRESULT Fire_OutRetvalVar( VARIANT *  val) {


...

CComVariant avarParams[1];
avarParams[0].pvarVal = val;
avarParams[0].vt = VT_BYREF | VT_VARIANT;
CComVariant varResult;
DISPPARAMS params = { avarParams, NULL, 1, 0 };
// go ahead and pass params here, but JScript will ignore
hr = pConnection->Invoke(2, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &params, &varResult, NULL, NULL);
// return value from event handler will be in varResult
::VariantCopy( val, &varResult );

...
}


JScript event handling code looks like this (notice the lack of parameter in the event handler function signature):
<script language="javascript" for="dan" event="OutRetvalVar">

alert( 'got OutRetvalVar (jscript), return true' );
return true;
</script>





Comments: Post a Comment

Home