XLL+ Class Library (6.3)

ComEvents Sample

Shows how to set up event handlers for COM events

Status

The code in this add-in demonstrates how to catch COM events using CXllApp::SetComEventHandler(). This technique is now deprecated and the unified event model should be used instead. See the following samples for examples of using the event model.

Overview

This project demonstrates how to use the CXllApp class to add event handler functions for COM Application events such as WorkbookOpen and SheetChange.

Features

The sample displays the following features:

Implementation

The following steps were significant in creating and completing the application.

  1. When the project was generated by the XLL+ AppWizard, the Override OnXllOpenEx() & OnXllClose()? check-box was ticked, so that instances of these two virtual methods were declared and generated automatically.
  2. Code was added to CComEventsApp::OnXllOpenEx to (i) create a menu (ii) register the COM event handlers and (iii) switch on event handling.
  3. Code was added to OnXllClose to destroy the menu.
  4. 14 event handler add-in functions were written, one for each of the events we wanted to trap. (Generally, you will not want to trap all these events; 2 or 3 usually suffices.) Each event handler's signature matched the specification in the documentation for CXllApp::SetComEventHandler.
  5. Each of the event handlers is registered using CXllApp::SetComEventHandler.
  6. Event handling is switched on and off using CXllApp::SetSinkEvents.

Classes and functions used

CXllApp | CXllApp::SetSinkEvents | CXllApp::SetComEventHandler | CXllApp::OnXllOpen | CXllApp::OnXllClose

Sample project

Each sample project is located in a sub-directory of the Samples directory of the XLL+ installation. To use the sample project, open the solution file ComEvents.sln or the project file ComEvents.vcproj.

You can enable debugging under Excel by using the Setup Debugging command in the XLL+ ToolWindow.

When delivered, the help files are excluded from the build. You can enable the help build by selecting the files ComEvents.help.xml and ComEvents.chm in the Solution Explorer, and using the right-click menu to view Properties. Select the page "Configuration Properties/General" and set the "Excluded from build" property to "No". See Generating help in the User Guide for more information.

See Also

List of Sample Projects