Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 2.6 KB

implementing-the-event-handling-interface.md

File metadata and controls

43 lines (30 loc) · 2.6 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Implementing the Event Handling Interface | Microsoft Docs
11/04/2016
cpp-windows
article
C++
ATL, event handling
event handling, ATL
interfaces, event and event sink
eb2a5b33-88dc-4ce3-bee0-c5c38ea050d7
10
mikeblome
mblome
ghogen

Implementing the Event Handling Interface

ATL helps you with all three elements required for handling events: implementing the event interface, advising the event source, and unadvising the event source. The precise steps you'll need to take depend on the type of the event interface and the performance requirements of your application.

The most common ways of implementing an interface using ATL are:

  • Deriving from a custom interface directly.

  • Deriving from IDispatchImpl for dual interfaces described in a type library.

  • Deriving from IDispEventImpl for dispinterfaces described in a type library.

  • Deriving from IDispEventSimpleImpl for dispinterfaces not described in a type library or when you want to improve efficiency by not loading the type information at run time.

If you are implementing a custom or dual interface, you should advise the event source by calling AtlAdvise or CComPtrBase::Advise. You will need to keep track of the cookie returned by the call yourself. Call AtlUnadvise to break the connection.

If you are implementing a dispinterface using IDispEventImpl or IDispEventSimpleImpl, you should advise the event source by calling IDispEventSimpleImpl::DispEventAdvise. Call IDispEventSimpleImpl::DispEventUnadvise to break the connection.

If you are using IDispEventImpl as a base class of a composite control, the event sources listed in the sink map will be advised and unadvised automatically using CComCompositeControl::AdviseSinkMap.

The IDispEventImpl and IDispEventSimpleImpl classes manage the cookie for you.

See Also

Event Handling