Late- Versus Early-Bound IDispatch
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
call.
Programs or languages that use IDispatch in the
manner described are known as
late-bound
,
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:
The
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
early-bound
.
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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access