Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
5.22 Mб
Скачать

13.3 Automation

Automation is available to both OLE objects and to ActiveX objects. For background, see the Overview. There are two categories of automation:

  • Automation (locally)

  • Remote Automation (over a network, using Distributed COM, or DCOM)

The remainder of this article concerns Automation. For Remote Automation, see the topic Remote Automation.

An Automation client is an application that can manipulate exposed objects belonging to another application. This is also called an Automation controller.

An Automation server is an application that exposes programmable objects to other applications. This is sometimes also called an "Automation component."

The server application exposes Automation objects. These Automation objects have properties and methods as their external interface. Properties are named attributes of the Automation object. Properties are like the data members of a C++ class. Methods are functions that work on an Automation object. Methods are like the public member functions of a C++ class.

Note Properties can have member functions that access them. A Get/Set function pair typically accesses a property of the object.

Passing Parameters in Automation

One of the difficulties in creating Automation methods is providing a uniform "safe" mechanism to pass data between automation servers and clients. Automation uses the VARIANT type to pass data. The VARIANT type is a tagged union. It has a data member for the value (this is an anonymous C++ union) and a data member indicating the type of information stored in the union. The VARIANT type supports a number of standard data types: 2- and 4-byte integers, 4- and 8-byte floating point numbers, strings, and Boolean values. In addition, it supports the HRESULT (OLE error codes), CURRENCY (a fixed-point numeric type), and DATE (absolute date and time) types, as well as pointers to IUnknown and IDispatch interfaces.

The VARIANT type is encapsulated in the COleVariant class. The supporting CURRENCY and DATE classes are encapsulated in the COleCurrency and COleDateTime classes.

Automation Clients

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 client is an application that can manipulate exposed objects belonging to another application. The application that exposes the objects is called the Automation server. The client manipulates the server application's objects by accessing those objects' properties and functions.

There are two types of Automation clients:

  • Clients that dynamically (at run time) acquire information about the properties and operations of the server.

  • Clients that possess static information (provided at compile time) that specifies the properties and operations of the server.

Clients of the first kind acquire information about the server's methods and properties by querying the OLE system's IDispatch mechanism. Although it is adequate to use for dynamic clients, IDispatch is difficult to use for static clients, where the objects being driven must be known at compile time. For static bound clients, the Microsoft Foundation classes provide the COleDispatchDriver class along with ClassWizard support.

Static bound clients use a proxy class that is statically linked with the client application. This class provides a type-safe C++ encapsulation of the server application's properties and operations.

The class COleDispatchDriver provides the principal support for the client side of Automation. Using ClassWizard, you create a class derived from COleDispatchDriver.

You then specify the type-library file describing the properties and functions of the server application's object. ClassWizard reads this file and creates the COleDispatchDriver-derived class, with member functions that your application can call to access the server application's objects in C++ in a type-safe manner. Additional functionality inherited from COleDispatchDriver simplifies the process of calling the proper Automation server.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]