Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to raise events with an Interface as argument

3 views
Skip to first unread message

Barzo

unread,
Oct 15, 2009, 2:24:31 PM10/15/09
to
Hi,

I have to raise an event from my library and, one of the parameter is
an IDispatch derived interface:


HRESULT Fire_OnStreamStateChanged( IWaveStream* Sender, short
new_state )
{

HRESULT hr = S_OK;
T * pThis = static_cast<T *>(this);
int cConnections = m_vec.GetSize();

for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();

CComQIPtr< IDispatch, &IID_IDispatch > pDispatch
( punkConnection );

if (pDispatch != NULL)
{
CComVariant avarParams[2];

....?????
....?????

VariantInit(&avarParams[0]);
avarParams[0].vt = ...???;
avarParams[1] = new_state;

DISPPARAMS params = { avarParams, NULL, 2, 0 };
hr = pDispatch->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &params, NULL, NULL, NULL);
}
}
return hr;
}


How I have to pack the WaveStream* Sender object?

Thanks for the suggestions!
Daniele.

Igor Tandetnik

unread,
Oct 15, 2009, 3:37:24 PM10/15/09
to
Barzo <dba...@gmail.com> wrote:
> I have to raise an event from my library and, one of the parameter is
> an IDispatch derived interface:
>
>
> HRESULT Fire_OnStreamStateChanged( IWaveStream* Sender, short
> new_state )
> {
> CComVariant avarParams[2];
>
> ....?????
> ....?????

avarParams[1] = Sender;

Or, if you want to pack it manually,

avarParams[1].vt = VT_DISPATCH;
(avarParams[1].pdispVal = Sender)->AddRef();

Remember that parameters should be packed into DISPPARAMS in reverse order: the last (rightmost) parameter goes into avarParams[0], next to last into avarParams[1] and so on.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925

Barzo

unread,
Oct 15, 2009, 4:04:09 PM10/15/09
to
On 15 Ott, 21:37, "Igor Tandetnik" <itandet...@mvps.org> wrote:
>
> avarParams[1] = Sender;
>
> Or, if you want to pack it manually,
>
> avarParams[1].vt = VT_DISPATCH;
> (avarParams[1].pdispVal = Sender)->AddRef();
>
> Remember that parameters should be packed into DISPPARAMS in reverse order: the last (rightmost) parameter goes into avarParams[0], next to last into avarParams[1] and so on.

Thanks a lot Igor!!
Daniele.

0 new messages