Automation Servers

HomeOverviewHow Do ISampleTutorial

Automation makes it possible for your application to manipulate objects implemented in another application, or to expose objects so they can be manipulated. An Automation server is an application that exposes programmable objects to other applications, which are called Automation clients. Exposing programmable objects enables clients to automate certain procedures by directly accessing the objects and functionality the server makes available.

Exposing objects this way is beneficial when applications provide functionality that is useful for other applications. For example, a word processor might expose its spell-checking functionality so that other programs can use it. Exposure of objects thus enables vendors to improve their applications’ functionality by using the ready-made functionality of other applications.

By exposing application functionality through a common, well-defined interface, Automation makes it possible to build applications in a single general programming language like Microsoft Visual Basic instead of in diverse, application-specific macro languages.

Support for Automation Servers

ClassWizard, AppWizard, and the framework all provide extensive support for Automation servers. They handle much of the overhead involved in making an Automation server, so you can focus your efforts on the functionality of your application.

The framework’s principal mechanism for supporting Automation is the dispatch map, a set of macros that expands into the declarations and calls needed to expose methods and properties for OLE. A typical dispatch map looks like this:

BEGIN_DISPATCH_MAP(CMyServerDoc, COleServerDoc)
    //{{AFX_DISPATCH_MAP(CMyServerDoc)
    DISP_PROPERTY(CMyServerDoc, "Msg", m_strMsg, VT_BSTR)
    DISP_FUNCTION(CMyServerDoc, "SetDirty", SetDirty, VT_EMPTY, VTS_I4)
    //}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

ClassWizard assists in maintaining dispatch maps. When you add a new method or property to a class, ClassWizard adds a corresponding DISP_FUNCTION or DISP_PROPERTY macro with parameters indicating the class name, external and internal names of the method or property, and data types.

ClassWizard also simplifies the declaration of Automation classes and the management of their properties and operations. When you use ClassWizard to add a class to your project, you specify its base class. If the base class allows Automation, ClassWizard displays controls you use to specify whether the new class should support Automation, whether it is “OLE Createable” (that is, whether objects of the class can be created on a request from a COM client), and the external name for the COM client to use.

ClassWizard then creates a class declaration, including the appropriate macros for the OLE features you have specified. ClassWizard also adds the skeleton code for implementation of your class’s member functions.

AppWizard simplifies the steps involved in getting your automation server application off the ground. If you select Automation support in AppWizard’s OLE Options page, AppWizard adds to your application’s InitInstance function the calls required to register your Automation objects and run your application as an Automation server.

What do you want to do?

See Also   ClassWizard: Automation Support, The MFC AppWizard (EXE version): Step-by-Step