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

For further details on GUIDs, see ‘The Microsoft<br />

Component Object Model’ section earlier in this<br />

chapter.<br />

IUID<br />

There are several methods in ArcObjects that take an IUID object as a parameter.<br />

An IUID object is a globally unique identifier object. It can be either a GUID, as<br />

shown in the example below, or a ProgID.<br />

IUIDPtr ipUID(CLSID_UID);<br />

IEnumLayerPtr ipEnumLayer;<br />

// Use IGeoFeatureLayer's GUID.<br />

hr = ipUID->put_Value(CComVariant(L"{E156D7E5-22AF-11D3-9F99-<br />

00C04F6BC78E}"));<br />

hr = ipMap->get_Layers(ipUID, VARIANT_TRUE, &ipEnumLayer);<br />

You might notice that the samples and scenarios<br />

do not follow the Good Error Handling practices<br />

outlined here. This is done simply to increase<br />

code readability since error checking is not the<br />

focus of those bits of code.<br />

ERROR HANDLING<br />

COM methods return an HRESULT to signify the success or failure of a call, as<br />

discussed in the ‘Developing with ArcObjects’ section earlier in this chapter.<br />

When you are programming with the C++ API, you should check the returned<br />

HRESULT of all calls to COM objects.<br />

There are a few common HRESULTs that can be returned.<br />

• S_OK signifies success.<br />

• E_FAIL indicates a failure.<br />

• E_NOTIMPL indicates a method is not implemented.<br />

There are some macros that can be used to test the returned HRESULT.<br />

• bool FAILED(HRESULT)<br />

For example, if the opening of a workspace in which you want to process<br />

data fails, you will not be able to use the data. At that point, you should exit<br />

the application to avoid a crash later.<br />

// Open the workspace.<br />

IWorkspaceFactoryPtr ipWorkspaceFactory(CLSID_RasterWorkspaceFactory);<br />

IWorkspacePtr ipWorkspace;<br />

HRESULT hr = ipWorkspaceFactory->OpenFromFile(inPath, 0, &ipWorkspace);<br />

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

{<br />

std::cerr

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

Saved successfully!

Ooh no, something went wrong!