ATL Event Handling Summary

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at ATL Event Handling Summary.

In general, handling COM events is a relatively simple process. There are three main steps:

  • Implement the event interface on your object.

  • Advise the event source that your object wants to receive events.

  • Unadvise the event source when your object no longer needs to receive events.

There are four main ways of implementing an interface using ATL.

Derive fromSuitable for Interface typeRequires you to implement all methods*Requires a type library at run time
The interfaceVtableYesNo
IDispatchImplDualYesYes
IDispEventImplDispinterfaceNoYes
IDispEventSimpleImplDispinterfaceNoNo

* When using ATL support classes, you are never required to implement the IUnknown or IDispatch methods manually.

There are three main ways of advising and unadvising an event source using ATL.

Advise functionUnadvise functionMost suitable for use withRequires you to keep track of a cookieComments
AtlAdvise, CComPtrBase::AdviseAtlUnadviseVtable or dual interfacesYesAtlAdvise is a global ATL function. CComPtrBase::Advise is used by CComPtr and CComQIPtr.
IDispEventSimpleImpl::DispEventAdviseIDispEventSimpleImpl::DispEventUnadviseIDispEventImpl or IDispEventSimpleImplNoFewer parameters than AtlAdvise since the base class does more work.
CComCompositeControl::AdviseSinkMap(TRUE)CComCompositeControl::AdviseSinkMap(FALSE)ActiveX controls in Composite controlsNoCComCompositeControl::AdviseSinkMap advises all entries in the event sink map. The same function unadvises the entries. This method is called automatically by the CComCompositeControl class.
CAxDialogImpl::AdviseSinkMap(TRUE)CAxDialogImpl::AdviseSinkMap(FALSE)ActiveX controls in a dialog boxNoCAxDialogImpl::AdviseSinkMap advises and unadvises all ActiveX controls in the dialog resource. This is done automatically for you.

Event Handling
Supporting IDispEventImpl

Show: