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

The main use of #import is to create C++ code for interface definitions and<br />

GUID constants (LIBID, CLSID, and IID) and to define smart pointers. The<br />

exclude (OLE_COLOR, OLE_HANDLE, VARTYPE) is required because<br />

Windows defines these to be unsigned longs, which conflicts with the <strong>ArcGIS</strong><br />

definition of long—this was required to support Visual Basic as a client of<br />

ArcObjects, since Visual Basic has no support for unsigned types. There are no<br />

issues with excluding these.<br />

You can view the code generated by #import in the type library header (.tlh) files,<br />

which are similar in format to a .h file. You may also find a type library implementation<br />

(.tli) file, which corresponds to a .cpp file. These files can be large but<br />

are only regenerated when the type libraries change.<br />

There are many type libraries at <strong>ArcGIS</strong> 9 for different functional areas. You can<br />

start by importing those that contain the definitions that you require. However,<br />

#import does not automatically include all other definitions that the imported<br />

type library requires. For example, when importing the type library esriGeometry,<br />

it will contain references to types that are defined in esriSystem, so esriSystem<br />

must be imported before esriGeometry.<br />

A complete list of library dependencies can be found in the Overview topic for<br />

each library.<br />

Choosing the minimum set of type libraries helps reduce compilation time, although<br />

this is not always significant. Here are some steps to help determine the<br />

minimum number of type libraries required:<br />

1. Do a compilation and look at the “missing type definition” errors generated<br />

from code, for example, ICommand not found.<br />

2. Place a #import statement for the library you need a reference for into your<br />

stdafx.h file. Use the LibraryLocator utility or component help to assist in this<br />

task.<br />

3. Compile the project a second time.<br />

4. The compiler will issue errors for types it cannot resolve in the imported type<br />

libraries; these are typically type definitions, such as WKSPoint or interfaces<br />

that are inherited into other interfaces. For example, if working with geometry<br />

objects, such as points, start by importing esriGeometry. The compiler will<br />

issue various errors such as:<br />

c:\temp\sample\debug\esrigeometry.tlh(869) : error C2061: syntax error :<br />

identifier 'WKSPoint'<br />

Looking up the definition of WKSPoint, you see it is defined in esriSystem.<br />

Therefore, importing esriSystem before esriGeometry will resolve all these<br />

issues.<br />

Below is a typical list of imports for working with the ActiveX controls.<br />

#pragma warning(push)<br />

#pragma warning(disable : 4192) /* Ignore warnings for types that are<br />

duplicated in win32 header files. */<br />

#pragma warning(disable : 4146) /* Ignore warnings for use of minus on<br />

unsigned types. */<br />

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

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

Saved successfully!

Ooh no, something went wrong!