Event Sources

In this section, you will create the ChatServer component that exposes a COM object called an event source. This COM object, which you’ll name ChatServerObj, supports the ISendMessage interface for ChatClients to post chat messages. It also supports a connection point associated with a callback interface called IReceiveMessage that is implemented by the ChatClient component (which will be developed in the Event Sinks section of this chapter). The ChatServer uses this callback interface to propagate chat messages to all chatters

Figure 10-2 shows the connections between a ChatClient and a ChatServerObj COM object. Notice that besides ISendMessage, ChatServerObj implements the IConnectionPointContainer interface to allow a client to find a particular supported connection point.

ChatServerObj is a source object and CoMsgSink is a sink object

Figure 10-2. ChatServerObj is a source object and CoMsgSink is a sink object

As you can see from Figure 10-2, the server component supports a connection point object that is associated with the IReceiveMessage interface, implemented by a client-side sink object, CoMsgSink. The client simply finds a connection point using the IConnectionPointContainer interface and tells the connection point that it wants to receive notifications by calling IConnectionPoint::Advise. The event source will make callbacks to the sink object at appropriate times.

Creating an Event Source Object

Our immediate goal is to create ...

Get Learning DCOM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.