Re: Accessing interfaces that are not associated with coclasses
Why on earth would you want to expose your event sink as a
publicly creatable COM object? These are by definition
internal private objects of the client. And as you have discovered
already, the ATL helper class for event dispinterfaces enforces
that by constructing a completely separate COM object in the
base template instantiation of IDispEvent[Simple]Impl. What
you need to do is create your event sink C++ object internally.
A member of another class, created on the heap via new, or
in some extreme cases even created on the stack, are all viable
possibilities... Make sure you get its lifetime correct though!
In most cases you'd want it as a member of the class that wants
to receive the events as it will unsubscribe before it's destroyed.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
<fueagk@leeds.ac.uk> wrote in message
news:1187698600.286662.302700@k79g2000hse.googlegroups.com...
I am trying to develop a vc++ client that can handle events through a
COM interface.
I have created a new class CInstrNotifySink and Inherit the ATL class
that implements the IDispatch methods using:
public IDispEventImpl<1, CInstrNotifySink, &Ecco::IID_IRTDUpdateEvent,
&Ecco::LIBID_Ecco,1,0>
I also define the ATL connection point event functions and callback
fns in the same way as in a previous client which I had working fine
for connecting to a different application. However, there are some
differences in the new application which boils down to how I access
the event interface before I use DispEventAdvise.
Previously it was straightforward:
AppOld::IRTDUpdateEventPtr m_pInstrNotifyObj;
HRESULT hr = S_OK;
CComQIPtr<IDispatch, &__uuidof(IDispatch)> ptr;
hr = ptr.CoCreateInstance (L"Ecco.Prices"); //create instance of
coclass
ptr->QueryInterface(AppOld::IID_IRTDUpdateEvent,
(void**)&m_pInstrNotifyObj);
if (hr==S_OK)
{
hr=DispEventAdvise(m_pInstrNotifyObj);
}
I could do this because here because AppOld::IRTDUpdateEvent is part
of the coclass which is created via hr = ptr.CoCreateInstance
(L"Ecco.Prices");
However, in the new application AppOld::IRTDUpdateEvent is not part of
any other coclass so I'm not sure how to do the equivalent. If I do
the above then the m_pInstrNotifyObj pointer is NULL.
To summarise:
Given
AppOld::IRTDUpdateEventPtr m_pInstrNotifyObj;
I want to access the pointer m_pInstrNotifyObj but the interface,
AppOld::IRTDUpdateEvent, is not part of another coclass to simply
CoCreateinstance of the parent class and use query interface for the
pointer (as shown above).
Any help is much appreciated as I am pretty new to COM