Article ID: 159041
Article Last Modified on 3/3/2005
119591 How to Obtain Microsoft Support Files from Online Services
EVENTH.EXE -d
IConnectionPointContainer IConnectionPoint EnumConnectionPoints EnumConnectionsThis sample provides a function called CreateStdCPContainer() that implements the above interfaces and a function called FireEvent() that the server can use to fire events to all clients who have connected to a connection point. The helper functions can be found in the Event.cpp and Event.h files and can be used by 32-bit applications only. These files are self-contained and can be added to any 32-bit project.
HRESULT CreateStdCPContainer(
IUnknown* punkController,
ITypeInfo* aptinfo[],
ULONG cTypeInfos,
DWORD dwFlags,
IUnknown** ppunkCPC)
The function creates a connection-point container object with connection
points corresponding to the array of typeinfos passed in. The newly created
object, which supports IConnectionPointContainer, is aggregated with
punkController. The implementation uses SAFEARRAYs as the data structure to
store the connection-point objects and the event sink pointers provided by
the COM clients.
[in] Points to the server's IUnknown. The connection-point container created by this function aggregates with this IUnknown.
[in] Array of pointers to typeinfos. Each one corresponds to an event interface/dispinterface that the object supports. Typically, an object has only one event interface/dispinterface.
[in] Size of aptinfo array. This is typically 1, unless the object has multiple event interfaces.
[in] Indicates the type of connection-point container to create. The two values allowed are CPTYPEFLAG_MULTICAST and CPTYPEFLAG_SINGLECAST. CPTYPEFLAG_MULTICAST indicates that multiple clients can connect their sinks to each connection point and the event will be fired to all those clients. CPTYPEFLAG_SINGLECAST indicates that only one client can connect its sink to each connection point and the event will be fired only to that client. These constants are defined in Event.h in this sample.
[out] Returns IUnknown* of the created connection-point container object. (This is the private unknown of the aggregate.)
S_OK Success.
E_INVALIDARG Invalid argument.
E_OUTOFMEMORY Memory allocation failed.
CreateStdCPContainer(this, &ptinfo, 1, CPTYPEFLAG_MULTICAST, &m_punkCPContainer); m_punkCPContainer->QueryInterface(IID_IConnectionPointContainer, (void**)&pcpc); pcpc->;FindConnectionPoint(riidEvents, &m_pcp);The COM server should implement its IUnknown::QueryInterface. Following is an example of how to handle a request for IID_IConnectionPointContainer:
if (iid == IID_IConnectionPointContainer)
return m_punkCPContainer->QueryInterface(iid, ppv);
After the server has aggregated with the connection-point container object
provided by CreateStdCPContainer, it can use the FireEvent() helper
function to fire events to the clients who have connected to a connection
point. Following is the documentation of FireEvent():
STDAPI FireEvent(IConnectionPoint FAR *pcp,
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo,
UINT FAR* puArgErr)
This fires the event specified by dispidMember to all sinks connected to
the pcp connection point. IDispatch::Invoke fires the event. Consequently,
the event sink in the client must implement IDispatch for this function to
work. If you do not want to use IDispatch to fire events, you must rewrite
this function but you can still use CreateStdCPContainer(). This function
does not stop firing events if the call to a specific event sink fails.
[in] The connection point for which events are going to be fired. This connection point must be obtained from the connection-point container created by CreateStdCPContainer().
S_OK Success
E_OUTOFMEMORY Memory Allocation failure
FireEvent(m_pcp, dispid, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dispparamsNoArgs, NULL, NULL, NULL);
nmake
nmake HOST=NT
149231 Marshaling Code for Connection Point Interfaces
158582 Configuring a non-DCOM server and client to use DCOM
Additional query words: Eventh kbfile
Keywords: kbserver kbdcom kbsample kbclientserver KB159041