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 />

COM allows these objects to be reused at a binary level, meaning that third-party<br />

developers do not require access to source code, header files, or object libraries to<br />

extend the system, even at the lowest level.<br />

COMPONENTS, OBJECTS, CLIENTS, AND SERVERS<br />

Different texts use the terms components, objects, clients, and servers to mean<br />

different things. (To add to the confusion, various texts refer to the same thing<br />

using all these terms.) Therefore, it is worthwhile to define some terminology.<br />

COM is a client/server architecture. The server (or object) provides some functionality,<br />

and the client uses that functionality. COM facilitates the communication<br />

between the client and the object. An object can, at the same time, be a<br />

server to a client and a client of some other object’s services.<br />

Objects are instances of COM classes that<br />

make services available for use by a client.<br />

Hence, it is normal to talk of clients and objects<br />

instead of clients and servers. These objects are<br />

often referred to as COM objects and component<br />

objects. This book will refer to them simply<br />

as objects.<br />

Client and server<br />

COM in-process server<br />

myDLL<br />

COM<br />

objects<br />

COM out-of-process server<br />

process space<br />

myEXE<br />

COM<br />

object<br />

s<br />

client<br />

server<br />

MyComputer<br />

Objects inside an out-of-process server are<br />

accessed by COM-supplied proxy objects, which<br />

make access transparent to the client.<br />

process space<br />

myEXE<br />

COM<br />

objects<br />

proxy<br />

object<br />

process space<br />

client<br />

server<br />

MyComputer<br />

Objects inside an in-process server are accessed<br />

directly by their clients.<br />

COM+ server<br />

process space<br />

yourEXE<br />

proxy<br />

object<br />

yourDLL<br />

process space<br />

yourEXE<br />

client<br />

server<br />

MyComputer<br />

YourComputer<br />

Objects inside an out-of-process server are<br />

accessed by COM-supplied proxy objects, which<br />

make access transparent to the client. The COM<br />

runtime handles the remoting layer.<br />

Client<br />

VBApp.exe<br />

Client/Server<br />

ArcMap.exe<br />

Server<br />

Map.dll<br />

The client and its servers can exist in the same process or in a different process<br />

space. In-process servers are packaged in DLL form, and these DLLs are loaded<br />

into the client’s address space when the client first accesses the server. Out-ofprocess<br />

servers are packaged in executables (EXE) and run in their own address<br />

space. COM makes the differences transparent to the client.<br />

When creating COM objects, the developer must be aware of the type of server<br />

that the objects will reside in, but if the creator of the object has implemented<br />

them correctly, the packaging does not affect the use of the objects by the client.<br />

There are pros and cons to each method of packaging that are symmetrically<br />

opposite. DLLs are faster to load into memory, and calling a DLL function is<br />

faster. EXEs, on the other hand, provide a more robust solution (if the server<br />

fails, the client will not crash), and security is better handled since the server has<br />

its own security context.<br />

In a distributed system, EXEs are more flexible, and it does not matter if the<br />

server has a different byte ordering from the client. The majority of ArcObjects<br />

servers are packaged as in-process servers (DLLs). Later, you will see the performance<br />

benefits associated with in-process servers.<br />

In a COM system, the client, or user of functionality, is completely isolated from<br />

the provider of that functionality, the object. All the client needs to know is that<br />

the functionality is available; with this knowledge, the client can make method<br />

calls to the object and expect the object to honor them. In this way, COM is said<br />

to act as a contract between client and object. If the object breaks that contract,<br />

the behavior of the system will be unspecified. In this way, COM development is<br />

based on trust between the implementer and the user of functionality.<br />

In the <strong>ArcGIS</strong> applications, there are many objects that provide, via their interfaces,<br />

thousands of properties and methods. When you use the ESRI object<br />

libraries, you can assume that all these properties and interfaces have been fully<br />

implemented, and if they are present on the object diagrams, they are there to<br />

use.<br />

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

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

Saved successfully!

Ooh no, something went wrong!