COM principles and applications----Automation (Automation) objects

Source: Internet
Author: User
Tags ole

1, Automation technology

Automation technology both previously mentioned in OLE Automation. Although automation technology is based on COM, automation is much more extensive than COM applications. On the one hand, automation inherits many of the benefits of COM, such as language-independent, process-transparent, etc., on the other hand, automation simplifies some of the underlying details of COM, such as the processing of attributes and methods, a set of data types dedicated to automation, and so on. Automation is also the foundation of OLE, so you can think of automation as a technology between COM and OLE. The core of automation is the IDispatch interface, and each automation object must implement the IDispatch interface. Automation technology is not complicated, it is actually a special case of COM.

2. Automation generation and development

COM's language independence is limited when it comes to the use of some weakly-typed high-level languages, and automation provides these high-level languages with an intuitive and friendly way for other programs to communicate with each other.

The development of automation technology is directly related to Visual Basic and VBA. First, VBA (or VBScript) has developed into a standard for most Microsoft application extensions, and second, the successful application of Microsoft Visual Basic development tools also drives the development of automation objects. Automated technology provides a shortcut for collaborative development of Visual Basic and other languages.

Through an automated programming interface, communication between different applications can take place either in VBA or VBScript, or even without knowing the concepts of Lie and RPC calls. Automation is a component technology located on the upper level (application tier) that can face end users, such as macro language programming.

The IDispatch interface of an Automation object can be used as the standard interface for OLE, because OLE already provides standard interface proxies and stub components, so automation objects can run in DLL components or in EXE components. If in a distributed environment, the automation object can be created or connected by a remote client.

3, properties and methods

Methods and properties are the two basic attributes of an automation object by means of the functional services provided by an Automation object, whereas attributes are the data characteristics of an Automation object.

Essentially, a property is a value that can be set or fetched.

Methods are much more flexible than properties, they can have 0 or more parameters, they can either set or get Object data, and most often do some action.

The properties and methods of an Automation object have a symbolic name, and the client program can access the properties or methods of the Automation object by name.

4. Type library and ODL

The type information of a Component object refers to some of the necessary information that it interacts with the outside world. This includes the CLSID of the component, the IID of its supported interfaces, each member function of the interface, the parameter and return value type of the member function, and so on, and the data type in the type information can also be a custom data type, such as the C language style structure, the Union , enumerations, and so on.

Microsoft has expanded IDL to form ODL (Object Description Language), which describes the type information of the Component object. Generally speaking, the type information of a Component object includes the type information of each interface and the type information of the object, and the description method of the interface type information is fully compatible with IDL. The interface type information is described using the interface or dispinterface keyword, and the object type information is described using the coclass keyword. Each ODL file can describe multiple component objects, which can be compiled with a MIDL or mktyplib tool to compile the type library. Typically, all objects in a component program are placed in a ODL file and the Library keyword is used to describe the repository information, including the ID of the type library (i.e. Libid), the language to use for the type library, the version, and so on. Other types of information can also be introduced in the ODL file using Importlib.

Compiling the ODL file with the MIDL utility can result in a type library file, followed by a TLB, or a corresponding. h header file.

The benefits of using type libraries are two points. One is VB or VBA can use the type library to browse the Component object's methods and properties, it can also use the type library to enhance access to properties and methods, and the second is that when implementing the IDispatch interface of an Automation object, the type library can be used to provide type information to the client, which allows us to avoid cumbersome type handling.

5, IDispatch interface

The member function invoke is a key function that the client must use to invoke the function to access the property or method, or to say that the invoke function is a command translator for the automation object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.