Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 1.99 KB

using-idispeventimpl.md

File metadata and controls

55 lines (37 loc) · 1.99 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: Using IDispEventImpl
Using IDispEventImpl (ATL)
08/19/2019
IDispEventImpl class, using
82d53b61-9d0d-45c5-aff9-2fafa468a9ca

Using IDispEventImpl

When using IDispEventImpl to handle events, you will need to:

  • Derive your class from IDispEventImpl.

  • Add an event sink map to your class.

  • Add entries to the event sink map using the SINK_ENTRY or SINK_ENTRY_EX macro.

  • Implement the methods that you're interested in handling.

  • Advise and unadvise the event source.

Example

The example below shows how to handle the DocumentChange event fired by Word's Application object. This event is defined as a method on the ApplicationEvents dispinterface.

The example is from the ATLEventHandling sample.

[ uuid(000209F7-0000-0000-C000-000000000046), hidden ]
dispinterface ApplicationEvents {
properties:
methods:
    [id(0x00000001), restricted, hidden]
    void Startup();

    [id(0x00000002)]
    void Quit();

    [id(0x00000003)]
    void DocumentChange();
};

The example uses #import to generate the required header files from Word's type library. If you want to use this example with other versions of Word, you must specify the correct mso dll file. For example, Office 2000 provides mso9.dll and OfficeXP provides mso.dll. This code is simplified from pch.h (stdafx.h in Visual Studio 2017 and earlier):

[!code-cppNVC_ATL_EventHandlingSample#1]

The following code appears in NotSoSimple.h. The relevant code is noted by comments:

[!code-cppNVC_ATL_EventHandlingSample#2]

See also

Event Handling
ATLEventHandling Sample