Implementing Multiple Dispatch Interfaces

AutoClik: Automation, Lesson 4

Tip   If you prefer working from a printed tutorial, see Copying and Printing in MSDN Library Help for details about printing a lesson, a set of topics, or a single topic.

In Step 2, you added properties and methods to AutoClik’s document dispatch interface, which was initially implemented by AppWizard. In Step 3, you create an entirely new CCmdTarget-derived class that is exposed by using a second dispatch interface.

In this step, you will:

AutoClik’s second dispatch interface, implemented in class CAutoClickPoint, is very simple. It has two properties: x and y. It has no methods. This dispatch interface has been included solely for tutorial reasons. AutoClik already fully exposes its behavior by using the document dispatch interface implemented in Step 2. CAutoClickPoint’s dispatch interface is introduced to illustrate techniques for managing multiple dispatch interfaces in the same application.

The design decision to split functionality into multiple dispatch interfaces is no different from design decisions to split a C++ application into multiple classes. This basic approach is so strong that the framework enforces a one-to-one relationship between dispatch interfaces and Automation-enabled CCmdTarget-derived classes.

AutoClik’s document dispatch interface will refer to the second dispatch interface in its implementation of the GetPosition and SetPosition methods. AutoClik’s document dispatch interface will expose the x and y coordinates using this Point interface as a programmatic alternative for the Automation client. The Automation client can get or set AutoClik’s x and y coordinates by using the GetX, GetY, SetX, and SetY methods implemented in Step 2. Alternatively, the Automation client can use the GetPosition and SetPosition methods implemented here in Step 3.