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.

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

// outFileName (or pass in a CComBSTR, which has been cast to a BSTR<br />

// to let the CComBSTR handle memory management).<br />

HRESULT GetFileFromFullPath(const char* inFullPath, BSTR *outFileName)<br />

{<br />

if (!inFullPath || !outFileName)<br />

return E_POINTER;<br />

*outFileName = 0;<br />

const char* name = strrchr(inFullPath, '/');<br />

if (name == 0)<br />

name = strrchr(inFullPath, '\\');<br />

// UNIX<br />

// Windows<br />

if (name == 0)<br />

return E_FAIL;<br />

name++;<br />

char* tmp = new char[strlen(name)+1];<br />

strcpy(tmp, name);<br />

CComBSTR bsTmp (tmp);<br />

delete[] tmp;<br />

if (!bsTmp)<br />

return E_OUTOFMEMORY;<br />

*outFileName = bsTmp.Detach();<br />

}<br />

return S_OK;<br />

5. Use the functions in PathUtilities.h to parse the input.<br />

a. Update RasterSlope.h to include PathUtilities.h so that you can use the<br />

functions you wrote above. Find:<br />

#include <br />

and below it, add:<br />

#include "PathUtilities.h"<br />

b. In RasterSlope.cpp’s main program, parse the input to get the path and the<br />

filename. Find:<br />

char* result = argv[2];<br />

return 0;<br />

Between these two lines, insert:<br />

// Parse path.<br />

CComBSTR sourceFilePath;<br />

CComBSTR sourceFileName;<br />

HRESULT hr = GetParentDirFromFullPath(source, &sourceFilePath);<br />

if (FAILED(hr) || sourceFilePath.Length()

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

Saved successfully!

Ooh no, something went wrong!