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.

VISUAL C++<br />

IXxxImpl<br />

CComXxxThreadModel<br />

CComObjectRootEx<br />

CMyObject<br />

IMyInt<br />

CComObject<br />

IMyInt2<br />

The hierarchical layers of ATL<br />

A more detailed discussion on Direct- To-COM<br />

follows in the section ‘Direct-To-COM smart<br />

types’.<br />

provides a set of wizards that extends the Visual Studio development environment.<br />

These wizards automate some of the tedious plumbing code that all ATL<br />

projects must have. The wizards include, but are not limited to, the following:<br />

• Application—Used to initialize an ATL C++ project.<br />

• Object—Used to create COM objects. Both C++ and IDL code are generated,<br />

along with the appropriate code to support the creation of the objects at<br />

runtime.<br />

• Property—Used to add properties to interfaces.<br />

• Method—Used to add methods to interfaces; both the Property and Method<br />

wizards require you to know some IDL syntax.<br />

• Interface Implementation—Used to implement stub functions for existing<br />

interfaces.<br />

• Connection Point Implement—Used to implement outbound events’ interfaces.<br />

Typically, these are accessed by a right-click on a project, class, or interface in<br />

Visual Studio Workspace/Class view.<br />

ATL provides base classes for implementing COM objects as well as implementations<br />

for some of the common COM interfaces, including IUnknown, IDispatch,<br />

and IClassFactory. There are also classes that provide support for ActiveX controls<br />

and their containers.<br />

ATL provides the required services for exposing ATL-based COM objects including<br />

registration, server lifetime, and class objects.<br />

These template classes build a hierarchy that sandwiches your class. These inheritances<br />

are shown to the left. The CComxxxThreadModel class supports thread-safe<br />

access to global, instance, and static data. The CComObjectRootEx class provides<br />

the behavior for the IUnknown methods. The interfaces at the second level represent<br />

the interfaces that the class will implement; these come in two varieties. The<br />

IxxxImpl interface contains ATL-supplied interfaces that also include an implementation;<br />

the other interfaces have pure virtual functions that must be fully<br />

implemented within your class. The CComObject class inherits your class; this class<br />

provides the implementation of the IUnknown methods along with the object<br />

instantiation and lifetime control.<br />

ATL and DTC<br />

Along with smart types, covered later in this chapter, Direct-To-COM (DTC)<br />

provides some useful compiler extensions you can use when creating ATL-based<br />

objects. The functions __declspec and __uuidof are two such functions, but the<br />

most useful is the #import command.<br />

COM interfaces are defined in IDL, then compiled by the Microsoft IDL compiler<br />

(MIDL.exe). This results in the creation of a type library and header files.<br />

The project uses these files automatically when compiling software that references<br />

these interfaces. This approach is limited in that, when working with<br />

interfaces, you must have access to the IDL files. As a developer of <strong>ArcGIS</strong>, you<br />

only have access to the <strong>ArcGIS</strong> type library information contained in .olb and<br />

100 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!