The process described for
IDispatch has one
obvious flaw: it seems highly inefficient, and it is! In many cases,
the inefficiency isn’t important; the objects you need to call
will often take longer to do their thing than it took to make the
Programs or languages that use
IDispatch in the
manner described are known as
because the binding of objects to methods or properties is done at
the last possible moment, as the call or property reference is made.
There is, however, a technique automation objects use to publish their object model in a type library. Type libraries define a set of interfaces a program can use to determine both the methods and properties themselves, and other useful information, such as the type of the parameters or return values. Languages or environments may be capable of using this information at compile-time to provide a better interface to the objects. The key benefits of knowing this information before it’s used are:
GetIDsOfNames() step described previously can
be removed, as the type information includes the integer ID of each
method or property.
Better type checking can be performed.
Languages that use the
IDispatch interface after
consulting type information are known as
Most COM-aware languages, including Visual Basic, Delphi, and Python have techniques that allow the programmer to choose between the binding models. Later in this chapter we discuss the differences when using Python.