Extension Implementing Events


This sample illustrates how you can respond to events from your extension. Here, the extension responds to IDocumentEvents. It begins listening when the extension is started up (IExtension::Startup), and stops listening when the extension is shut down (IExtension::Shutdown).

As there is a definite point when the extension is disconnected from the event source, and as this point occurs before the application tries to destroy the extension, there is no need for an intermediate sink object.

How to use:

    Register the extension:

  1. Open this sample's workspace and change the paths to esriCore.olb and ArcCATIDs.h in StdAfx.h so that they point to your ArcGIS installation.
  2. Build this sample's dll. This also registers the dll and adds it to the appropriate component categories.
  3. Close and re-start ArcMap.

    Use the extension:

  1. Trigger Document events by opening a new document, right-clicking for the context menu, switching to layout view, etc.
  2. When you trigger an event by your actions in ArcMap, you will get a message box from the extension with details of the event.
  3. When you close ArcMap, the extension disconnects from the event source.
  4. To remove the extension, open Categories.exe and navigate to 'ESRI Mx Extensions'. Select 'TestExtension Class' and hit 'Remove Object'. Alternatively, you can unregister this sample's DLL.


Difficulty: Intermediate

Visual C++
File Description
TestExtension.cpp Implementation file for the Extension Implementing Events.
TestExtension.h Header file for the Extension Implementing Events.
TestExtension.rgs Registry script file for the Extension Implementing Events.
ExtensionImplementingEvents.dsp Project file.
ExtensionImplementingEvents.dsw Workspace file.
ExtensionImplementingEvents.dll Compiled DLL for project.
ExtensionImplementingEvents.cpp Implementation of DLL Exports.
ExtensionImplementingEvents.def Module Definition file, listing exported functions.
ExtensionImplementingEvents.idl The IDL file for the sample.
ExtensionImplementingEvents.rc Resource file.
ExtensionImplementingEvents.mak Make file for Project.
ExtensionImplementingEventsps.def Module definition file for proxy-stub Code.
ExtensionImplementingEventsps.mk Make file for proxy-stub code.
resource.h Resource file.
StdAfx.h Header file that includes standard system include files.
StdAfx.cpp Source file that includes just the standard includes.

Key Interfaces: IExtension, IExtensionConfig, IApplication, IDocument, IDocumentEvents