Passing interface derived from IDispatch as a parameter
Hello,
Is it possible to get a dual interface (not IDispatch!), passed as a
parameter to Invoke, marshaled correctly?
I've got a source dispinterface with a method defined like this:
[id(1), helpstring("method notify")] HRESULT notify([in] IMySender
*sender);
where IMySender is:
[
object,
uuid(...),
dual,
nonextensible,
pointer_default(unique)
]
interface IMySender : IDispatch
{
//...
}
So in the CP implementation I've got a code like this:
HRESULT Fire_Notify(int id, IMySender *sender)
{
//iterate through connections...
...
CComVariant avarParams[1];
avarParams[0] = sender;
avarParams[0].vt = VT_DISPATCH;
CComVariant varResult;
DISPPARAMS params = { avarParams, NULL, 1, 0 };
hr = pConnection->Invoke(id, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL);
...
}
However, this doesn't work when the event is fired into another
apartment: IMySender is not marshaled well (only IDispatch part of it
is actually marshaled), so that any call to its methods crashes.
"Dirty" workaround is to perform explicit QI:
void onNotify(IMySender *sender)
{
IDispatch *disp = sender;
CComQIPtr<IMySender> goodSender(disp);
goodSender->...;
}
My question is whether it's possible to pass "typed" interface
correctly in such situation?