XLL+ Class Library

ComEvents Sample

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.

Functions used

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

Project files

If you are using MS Developer Studio 6, then you should open the project file ComEvents.dsp.

If you are using MS Visual Studio .NET 2002, then you should open the solution file ComEvents.sln or the project file ComEvents.vcproj.

If you are using MS Visual Studio .NET 2003, then you should open the solution file ComEvents71.sln or the project file ComEvents71.vcproj.

If you are using MS Visual Studio 2005, then you should open the solution file ComEvents8.sln or the project file ComEvents8.vcproj.

See Also

List of Sample Projects | Samples and Walkthroughs