
Fire an Event, sink a event - Help!
Help!! I've got an ATL COM simple object that fires an event, the interface
for it looks something like this:
// An outgoing interface for well segments
dispinterface _WellSegmentEvents
{
properties:
methods:
[id(1), helpstring("method WellSegmentChanged")] void
WellSegmentChanged();
};
And then the actual object that fires these events is here:
coclass PipeSegment
{
[default] interface IPipeSegment;
[default, source] interface _WellSegmentEvents;
interface IWellSegment;
};
I also have a container that will hold a bunch of these PipeSegmnt objects
via an "Add" method that takes an IWellSegment interface,and stics them into
a vector. The container then gives these interfaces back to the user via a
Segment(long index) method. What I want to do is have the container handle
the events that are fired by well segments, so I tried inheriting from
IDispEventImpl, like this in the coclass of my container:
class ATL_NO_VTABLE CWellSegmentList :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CWellSegmentList, &CLSID_WellSegmentList>,
public IDispatchImpl<IWellSegmentList, &IID_IWellSegmentList,
&LIBID_SEGMENTSLib>,
public CProxy_WellSegmentListEvents< CWellSegmentList >,
public IConnectionPointContainerImpl<CWellSegmentList>,
// Stuff for implementing events and stuff . . .
public IDispEventImpl<1, CWellSegmentList, &DIID__WellSegmentEvents,
&LIBID_SEGMENTSLib, 1, 0 >
{
--snip--
// Sink for incoming events . . .
BEGIN_SINK_MAP(CWellSegmentList)
SINK_ENTRY_EX(1, DIID__WellSegmentEvents, 0x1, OnWellSegmentChanged)
END_SINK_MAP()
Quote:
};
Here's what happens when I add a segment to the container:
STDMETHODIMP CWellSegmentList::Add(IWellSegment *pSegment)
{
// Add the segment to the vector
m_vector.push_back(pSegment);
pSegment->AddRef();
// TODO - Is this correct?? Establish a connection to the well segment
event system
DispEventAdvise(pSegment);
// Adios
return S_OK;
Quote:
}
Later, I got an interface to one of the segments fro the container, and
changed one of its properties, which should cause the segment to fire a
changed event, that would be handled by the container. I stepped through
the code up to the point where the list of connections in the CP interface
of the segment are iterated through, and the call Invoke is made on the
client. There was exactly one entry in the connection list (my container,
so that's right), that the segment proxy found, then there's a call to a
function named GetFuncInfoFromId, which returns an HRESULT of "Library not
registered", and it exits prematurely before getting to the part where it
actually invokes the method of the IDispatch interface on the client. I
don't know what I should do next, but I think there is something wrong wit
the way I am specializing the IDispEventImpl template. anyone have any idea
what would cause the event handling mechanism inherited from IDispImpl to
fail so gracefully? There is nothing tragic happening, no assertions or
access violations, but after the event gets fired by the segment, it just
goes away. Just exitsbefore invoking anything. Is this the correct
approach? This may be a dumb question, but wheredo i verify the major and
minor version of the type library? The version info block lists a file
version of 1, 0, 0, 1, I think, but I don't know which part is which, just
have a suspicion I am giving the wrong parameters to the template.
Thanks in advance for any advice,
Aaron