I want to get a proper IDispatch pointer then cast it to CMyDispatch pointer and have my way with it later.
i.e. in javascript I want to do something like this:
var x = external.obj.x;
var y = external.obj.y;
external.obj.x = y;
where x and y are instances of CMyDispatch.
CMyDispatch is returned to javascript this way:
STDMETHODIMP CMyDispatch::Invoke(DISPID dispIdMember, REFIID, LCID, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pVarResult,
EXCEPINFO*, UINT*) {
if( pVarResult )
{
CMyDispatch* pDisp = new CMyDispatch();
CComVariant val( pDisp );
val.Detach( pVarResult );
}
return S_OK;
}
In CMyDispatch.Invoke() with DISPATCH_PROPERTYPUT flag I want to get CMyDispatch instance that holds y value.
When using the following code, pDispatch is set to some garbage:
STDMETHODIMP CMyDispatch::Invoke(DISPID dispIdMember, REFIID, LCID, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pVarResult,
EXCEPINFO*, UINT*) {
ASSERT( pDispParams->cArgs == 1 );
ASSERT( VT_DISPATCH == pDispParams->rgvarg[0].vt );
IDispatch* pDisp = ( pDispParams->rgvarg[0].pdispVal ); // <-- garbage
CMyDispatch* pDispatch = (CMyDispatch*) pDisp; // <-- garbage
return S_OK;
}
What should I do to get proper CMyDispatch pointer? Thank you.