How to Use the C++ SamplesThis topic provides general information on how to use the C++ samples. Additionally, each sample has a help topic with detailed instructions on how to use that particular sample. If you did not selected to install the samples when you installed your ArcGIS Engine, see Installing the samples. There are two types of samples: tips and tools. A tip is a single function which you will use by pasting simply pasting the function into your own code and calling it. A tool is composed of one or more files and will be as simple as a single function or as complex as an entire application. This document addresses how to use the code provided in a tool. To use an ArcObjects tool which is not a complete application, but instead simply one or more functions in their own files, you will incorporate the provided files into your own code. This procedure is outlined in Using Sample Functions, and will result in you creating your own complete ArcObjects application. To use a complete ArcObjects tool application, either from a tool or your own code, you have two development options on Windows:
You can also choose to use the provided executables which install with each sample that is a complete application. Installing the SamplesThe ArcGIS developer samples are not included in the 'typical' installation of the ArcGIS Engine Developer Kit. If you do not have them installed, rerun the Developer Kit install wizard, choose Custom or Modify, and select the samples feature under Software Developer Kit. The Code Exchange on the ESRI Developer Network (EDN) Web site (http://edn.esri.com) has a download for each sample which contains all of the files associated with the sample. It also has new samples added since the last release. Location of Sample Source Code and Provided ExecutablesThe source code for C++ samples is located throughout the 'arcgis/developerkit/samples/' folder at your ArcGIS Engine install location. The samples folder contains the top-level samples folders (for example, "Controls"). In each of those folders are compressed files whose names match the sample names, with the addition of the implementation language. For example, the Motif C++ source for a sample located in the TOC at Controls > MapControl and named MapTocToolbar would be found in 'arcgis/developerkit/samples/controls/MapTocToolbarMotif_Cpp.zip'. There are executables provided with the samples which are included in the compressed files with the code. The name of the exe matches that of the parent directory of the code folder for that sample. Command Line Applications Control Applications Using Provided ExecutablesIf you do not want to compile the samples on your own but instead wish to use the provided executables, you can do so by running that executable from the command line, making sure you pass in appropriate arguments. For example, to run the sample "Geodatabase > Accessing_Data > Query_a_shapefile" on a machine with the samples
installed and this particular sample uncompressed, start by opening a command prompt. This can be done
by going to the Start menu > run and typing in cmd. At the prompt go to the directory with the exe by typing
the path to where you uncompressed it. For example:
To run the sample application on the shapefile located at \data\shapefile type:
Using Sample FunctionsSome tools only include a sample function or functions. These have been provided for you to use in your own applications. If a sample tool only provides *.h and *.cpp files, and no Makefile or project files, it is a sample function and will need to be called from within your own code, as outlined below.
Using ArcObjects Applications in Microsoft's Visual Studio Development Environment 6.0 or .NET 2003 (7.1)Setting Up Your CompilerTo use the samples, your compiler must be set up to run ArcObjects code. To run the samples from within Microsoft's Visual Studio you will just need to open the code in that environment. No additional setup is needed. Compiling Sample ApplicationsOften you will be able to use the executable provided with a sample, in which case you can skip this step and proceed to Running Sample Applications. However, you will need to open the provided project and compile the application yourself if you need (or want) to modify the source code.
The sample is now ready for use. Running Sample ApplicationsTo run in Microsoft Visual Studio 6.0, open the vs6.dsw in the vs6 subfolder of the sample. To run in Microsoft Visual Studio .NET, use the vs7.sln file which is in the vs7 subfolder of the sample. First you should refer to the How To Use: C++ and Requires sections in the help topic of the sample you wish to use. If you need to do anything specific to use the particular sample you have chosen, follow those steps. For example, the sample may have specific license or data requirements indicated in those sections. Next add any necessary arguments to your project by customizing your project settings. Make sure the configuration you are working on is selected in the configuration combobox.
Now you are ready to run the sample! You will run it by pressing Using ArcObjects Applications from the Windows Command LineSetting Up Your CompilerTo use the samples, your compiler must be set up to run ArcObjects code. To use the samples from the command line, you will need to set up a command line prompt from which the development tools of Visual Studio are available. By default the command line build tools of Visual Studio are not available but a batch file, vcvars32.bat, is provided to make them available. To run the Visual Studio 6.0 compiler, complete the following steps:
You will need to run the batch file must be run each time you open a new command prompt. For detailed directions on how to create a batch file that will run the Visual Studio 6.0 version of vccars32.bat for you, see the help located in Development Environments -> C++ -> Platform Configuration -> Configuring Windows. To run the Visual Studio .NET 2003 compiler, complete the following steps:
Compiling Sample ApplicationsOften you will be able to use the executable provided with a sample, in which case you can skip this step and proceed to Running Sample Applications. However, you will need to compile the application yourself if you need (or want) to modify the source code. To compile from the command line, you will use a Makefile, Makefile.Windows, which is included
with each sample application in the makefiles subdirectory. If you did not install to the default location, you
will need to edit Makefile.Windows so that the lines:
Now compile the sample by typing the following at the command line which has access to the
Visual Studio development tools (as set up above):
The sample is now ready to use. Running Sample ApplicationsFirst you should refer to the How To Use: C++ and Requires sections in the help topic of the sample you wish to use. If you need to do anything specific to use the particular sample you have chosen, follow those steps. For example, the sample may have specific license or data requirements indicated in those sections. You can run the samples by typing the name of the executable at the command line, followed by any necessary arguments. If you are unsure of the arguments needed, simply type in the name of the executable and attempt to run it. If arguments are needed, a usage message will be displayed. However, it is recommended that you run the samples through the Makefile, Makefile.Windows, which is provided with each sample application in makefiles subdirectory. To use it, you will need to edit Makefile.Windows to provide any required arguments. For example, if a single shapefile is needed, you would modify:
replacing Now you are ready to run the application. Execute the application by typing the following at the configured command line:
Using ArcObjects Applications on Solaris and LinuxSetting Up Your CompilerTo use the samples, your compiler must be set up to run ArcObjects code. To do this,
you will source Compiling Sample ApplicationsOften you will be able to use the executable provided with a sample, in which case you can skip this step and proceed to Running Sample Applications. However, you will need to compile the application yourself if you need (or want) to modify the source code. You will use a Makefile to compile. There are makefiles included with each sample application:
Even if you did not install to the default location, the makefile should be able to compile the sample without any changes. However, if you are not having luck with it, you may need to edit the makefile so that the lines:
point to the locations of those directories and libraries on your computer. Now compile the sample by typing the following, using the makefile appropriate for your platform:
The sample is now ready to use. Running Sample ApplicationsFirst you should refer to the How To Use: C++ and Requires sections in the help topic of the sample you wish to use. If you need to do anything specific to use the particular sample you have chosen, follow those steps. For example, the sample may have specific license or data requirements indicated in those sections. You can run the samples by typing the name of the executable at the command line, followed by any necessary arguments. If you are unsure of the arguments needed, simply type in the name of the executable and attempt to run it. If arguments are needed, a usage message will be displayed. However, it is recommended that you run the samples through the makefile. You will need to edit
the makefile to provide any required arguments. For example, if a single shapefile is needed,
you would modify:
Now you are ready to run the application. Execute the application by typing the following,
using the makefile name appropriate for your platform:
|
SearchMost Popular ArcScripts
Other Resources |