18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

THE MICROSOFT COMPONENT OBJECT MODEL<br />

Binding is the term given to the process of<br />

matching the location of a function given a<br />

pointer to an object.<br />

Binding type<br />

In process<br />

DLL<br />

Out of process<br />

DLL<br />

Late binding 22,250 5,000<br />

Custom vTable binding 825,000 20,000<br />

This table shows the number of function calls<br />

that can be made per second on a typical<br />

Pentium ® III machine.<br />

IUnknown<br />

IMap<br />

IUnknown<br />

IDispatch<br />

IApplication<br />

Custom - Map<br />

vTable<br />

QueryInterface<br />

AddRef<br />

Release<br />

Name<br />

Description<br />

AreaOfInterest<br />

Dual - Application<br />

vTable<br />

QueryInterface<br />

AddRef<br />

Release<br />

GetTypeInfoCount<br />

GetTypeInfo<br />

GetIDsOfNames<br />

Invoke<br />

Name<br />

Document<br />

StatusBar<br />

These diagrams summarize the custom and<br />

IDispatch interfaces for two classes in<br />

ArcObjects. The layout of the vTable displays the<br />

differences. It also illustrates the importance of<br />

implementing all methods—if one method is<br />

missing, the vTable will have the wrong layout,<br />

and hence, the wrong function pointer would be<br />

returned to the client, resulting in a system<br />

crash.<br />

IDispatch interface<br />

COM supports three types of binding:<br />

• Late. This is where type discovery is left until runtime. Method calls made by<br />

the client but not implemented by the object will fail at execution time.<br />

• ID. Method IDs are stored at compile time, but execution of the method is<br />

still performed through a higher-level function.<br />

• Custom vTable (early). Binding is performed at compile time. The client can<br />

then make method calls directly into the object.<br />

The IDispatch interface supports late- and ID-binding languages. The IDispatch<br />

interface has methods that allow clients to ask the object what methods it supports.<br />

Assuming the required method is supported, the client executes the method by<br />

calling the IDispatch::Invoke method. This method, in turn, calls the required<br />

method and returns the status and any parameters back to the client on completion<br />

of the method call.<br />

Clearly, this is not the most efficient way to make calls on a COM object. Late<br />

binding requires a call to the object to retrieve the list of method IDs; the client<br />

must then construct the call to the Invoke method and call it. The Invoke method<br />

must then unpack the method parameters and call the function.<br />

All these steps add significant overhead to the time it takes to execute a method.<br />

In addition, every object must have an implementation for IDispatch, which<br />

makes all objects larger and adds to their development time.<br />

ID binding offers a slight improvement over late binding in that the method IDs<br />

are cached at compile time, which means the initial call to retrieve the IDs is not<br />

required. However, there is still significant call overhead because the<br />

IDispatch::Invoke method is still called to execute the required method on the<br />

object.<br />

Early binding, often referred to as custom vTable binding, does not use the<br />

IDispatch interface. Instead, a type library provides the required information at<br />

compile time to allow the client to know the layout of the server object. At<br />

runtime, the client makes method calls directly into the object. This is the fastest<br />

method of calling object methods and also has the benefit of compile-time type<br />

checking.<br />

Objects that support both IDispatch and custom vTable are referred to as dual<br />

interface objects. The object classes within the ESRI object libraries do not<br />

implement the IDispatch interface; this means that these object libraries cannot be<br />

used with late-binding scripting languages, such as JavaScript or VBScript, since<br />

these languages require that all COM servers accessed support the IDispatch<br />

interface.<br />

Careful examination of the <strong>ArcGIS</strong> class diagrams indicates that the Application<br />

objects support IDispatch because there is a requirement in VBA for the IDispatch<br />

interface.<br />

Chapter 4 • <strong>Developer</strong> environments • 65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!