Platform SDK: CDO 1.2.1 |
IDispatch is a COM interface that is designed in such a way that it can call virtually any other COM interface. Developers working in Microsoft® Visual Basic® often cannot call COM interfaces directly, as they would from C or C++. However, when their tool supports IDispatch, as Visual Basic does, and when the object they want to call supports IDispatch, they can call its COM interfaces indirectly.
The main method offered by IDispatch is called Invoke. This method adds a level of indirection to the control flow of the Component Object Model. In the standard COM model, an object obtains a pointer to an interface and then calls a member method of the interface. With IDispatch, instead of directly calling the member method, the program calls IDispatch::Invoke, and IDispatch::Invoke calls the member method for you.
Invoke is a general method-calling machine. Its parameters include a value that identifies the method that is to be called and the parameters that are to be sent to it. In order to be able to handle the wide variety of parameters that other COM methods use, Invoke uses a self-describing data structure called a VARIANTARG.
The VARIANTARG structure contains two parts: a type field, which represents the data type, and a data field, which represents the actual value of the data. The data type, known also as variant type, contains a constant such as VT_I2 or VT_DATE, which defines valid values for the data types. For more information on variant types, see the Type property of the Field object.
Associated with IDispatch is the notion of a type library. The type library publishes information about an interface so that it is available to Visual Basic programs. The type library, or typelib, contains the same kind of information that C or C++ programmers would obtain from a header file: the name of the method and the sequence and types of its parameters.
An executable file or DLL that exposes IDispatch and its type library is known as an Automation server. The CDO Library and the CDO Rendering Library are both Automation servers. In version 1.1 and later they are also in-process servers, residing in .DLL files and linking dynamically with the calling modules.