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.

BUILDING A COMMAND-LINE C++ APPLICATION<br />

}<br />

AoExit(0);<br />

return 0;<br />

AoExit(0);<br />

return 0;<br />

}<br />

3. Write helper functions that initialize and shut down the engine. These are<br />

general functions that you can use in any command-line application.<br />

a. In RasterSlope.h:<br />

#include <br />

bool InitializeWithExtension(esriLicenseProductCode product,<br />

esriLicenseExtensionCode extension);<br />

void ShutdownApp(esriLicenseExtensionCode license);<br />

b. At the bottom of RasterSlope.cpp:<br />

bool InitializeWithExtension(esriLicenseProductCode product,<br />

esriLicenseExtensionCode extension)<br />

{<br />

::AoInitialize(0);<br />

IAoInitializePtr ipInit(CLSID_AoInitialize);<br />

esriLicenseStatus licenseStatus = esriLicenseFailure;<br />

ipInit->IsExtensionCodeAvailable(product, extension, &licenseStatus);<br />

if (licenseStatus == esriLicenseAvailable)<br />

{<br />

ipInit->Initialize(product, &licenseStatus);<br />

if (licenseStatus == esriLicenseCheckedOut)<br />

ipInit->CheckOutExtension(extension, &licenseStatus);<br />

}<br />

return (licenseStatus == esriLicenseCheckedOut);<br />

}<br />

It appears that a new instance of AoInitialize is<br />

created in ShutdownApp(). However, it is a<br />

singleton object and so returns a pointer to the<br />

AoInitialize object that was previously created.<br />

void ShutdownApp(esriLicenseExtensionCode license)<br />

{<br />

// Scope ipInit so released before AoUninitialize call<br />

{<br />

IAoInitializePtr ipInit(CLSID_AoInitialize);<br />

esriLicenseStatus status;<br />

ipInit->CheckInExtension(license, &status);<br />

ipInit->Shutdown();<br />

}<br />

}<br />

::AoUninitialize();<br />

Command-line applications can be run against any <strong>ArcGIS</strong> <strong>Engine</strong> installation—<br />

Runtime or developer kit—or any installation of the <strong>ArcGIS</strong> Desktop products<br />

(ArcView, ArcEditor, or ArcInfo). However, this particular application requires a<br />

Spatial license in addition to the core license. Depending on the core product<br />

Chapter 6 • <strong>Developer</strong> scenarios • 435

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

Saved successfully!

Ooh no, something went wrong!