Click here to Skip to main content
15,883,647 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 576K   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.idl : IDL source for EventFiringObject.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (EventFiringObject.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
	[
		object,
		uuid(8E396CC0-A266-481E-B6B4-0CB564DAA3BC),
		dual,
		helpstring("IEventFiringObject Interface"),
		pointer_default(unique)
	]
	interface IEventFiringObject : IDispatch
	{
		[id(1), helpstring("method TestFunction")] HRESULT TestFunction([in] long lValue);
	};

[
	uuid(0B199966-76EA-479F-881D-ED7CB5F3457B),
	version(1.0),
	helpstring("EventFiringObject 1.0 Type Library")
]
library EVENTFIRINGOBJECTLib
{
	importlib("stdole32.tlb");
	importlib("stdole2.tlb");

	[
		uuid(32F2B52C-1C07-43BC-879B-04C70A7FA148),
		helpstring("_IEventFiringObjectEvents Interface")
	]
	dispinterface _IEventFiringObjectEvents
	{
		properties:
		methods:
		[id(1), helpstring("method Event1")] HRESULT Event1([in] long lValue);
	};

	[
		uuid(A17BC235-A924-4FFE-8D96-22068CEA9959),
		helpstring("EventFiringObject Class")
	]
	coclass EventFiringObject
	{
		[default] interface IEventFiringObject;
		[default, source] dispinterface _IEventFiringObjectEvents;
	};
};

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