18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C++ APPLICATION PROGRAMMING INTERFACE<br />

Notice the call to AddRef. This is required to<br />

ensure that resources are managed properly.<br />

}<br />

IWorkspacePtr ipWork;<br />

hr = ipWorkspaceFactory->OpenFromFile(CComBSTR(path), 0, &ipWork);<br />

if (FAILED(hr) || ipWork == 0)<br />

return E_FAIL;<br />

// Initialize ipTinWorkspace with ipWork.<br />

ITinWorkspacePtr ipTinWorkspace(ipWork);<br />

*ppTinWorkspace = ipTinWorkspace;<br />

// AddRef() if the assignment worked.<br />

if (*ppTinWorkspace)<br />

(*ppTinWorkspace)->AddRef();<br />

return hr;<br />

ESRI System interfaces<br />

The System library within <strong>ArcGIS</strong> <strong>Engine</strong>, which is included with ArcSDK.h,<br />

contains a number of interfaces that simplify programming. It contains components<br />

that expose services used by the other <strong>ArcGIS</strong> libraries.<br />

Groups of objects in interfaces without STL<br />

ArcObjects contains several interfaces for managing groups of objects. Although<br />

they are not all discussed here, the examples given illustrate some that can greatly<br />

simplify your work with COM objects in C++. Standard Template Library types<br />

similar to some of these exist; however, these interfaces are often simpler than<br />

their STL counterparts and are already set up to be used with COM objects. For<br />

additional details on any of the interfaces below, see <strong>ArcGIS</strong> <strong>Developer</strong> Help for<br />

C++.<br />

• IArray—provides access to members that control a simple array of objects.<br />

There are multiple related interfaces, such as IDoubleArray and IVariantArray.<br />

The following code snippet shows how to add the geometries of the features<br />

in a FeatureCursor to an array.<br />

// ipFeatureLayer is of type IFeatureLayerPtr and ipQueryFilter is of<br />

// type IQueryFilterPtr. Both have already been declared and<br />

// instantiated.<br />

IArrayPtr ipCacheArray (CLSID_Array);<br />

IFeatureCursorPtr ipFeatureCursor;<br />

ipFeatureLayer->Search(ipQueryFilter, VARIANT_FALSE, &ipFeatureCursor);<br />

IFeaturePtr ipFeature;<br />

while (ipFeatureCursor->NextFeature(&ipFeature) == S_OK)<br />

{<br />

IGeometryPtr ipGeom;<br />

ipFeature->get_ShapeCopy(&ipGeom);<br />

ipCacheArray->Add((IUnknownPtr) ipGeom);<br />

}<br />

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

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

Saved successfully!

Ooh no, something went wrong!