Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C++

Understanding COM Event Handling

Rate me:
Please Sign up or sign in to vote.
4.91/5 (96 votes)
9 Dec 2004CPOL19 min read 576.4K   7.4K   219  
Learn the fundamental principles of COM Event Handling via a C++ template class that allows for generic handling of dispinterface COM events.
// EventFiringObject_Impl.h : Declaration of the CEventFiringObject

#ifndef __EVENTFIRINGOBJECT_H_
#define __EVENTFIRINGOBJECT_H_

#include "resource.h"       // main symbols
#include "EventFiringObjectCP.h"

/////////////////////////////////////////////////////////////////////////////
// CEventFiringObject
class ATL_NO_VTABLE CEventFiringObject : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CEventFiringObject, &CLSID_EventFiringObject>,
	public ISupportErrorInfo,
	public IConnectionPointContainerImpl<CEventFiringObject>,
	public IDispatchImpl<IEventFiringObject, &IID_IEventFiringObject, &LIBID_EVENTFIRINGOBJECTLib>,
	public CProxy_IEventFiringObjectEvents< CEventFiringObject >
{
public:
	CEventFiringObject()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_EVENTFIRINGOBJECT)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CEventFiringObject)
	COM_INTERFACE_ENTRY(IEventFiringObject)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
	COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CEventFiringObject)
CONNECTION_POINT_ENTRY(DIID__IEventFiringObjectEvents)
END_CONNECTION_POINT_MAP()


// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// IEventFiringObject
public:
	STDMETHOD(TestFunction)(/*[in]*/ long lValue);
};

#endif //__EVENTFIRINGOBJECT_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer NEC
Singapore Singapore
Lim Bio Liong is a Specialist at a leading Software House in Singapore.

Bio has been in software development for over 10 years. He specialises in C/C++ programming and Windows software development.

Bio has also done device-driver development and enjoys low-level programming. Bio has recently picked up C# programming and has been researching in this area.

Comments and Discussions