The ArcGIS Software Developer Kits (SDKs) contain a number of samples for you to use. Each sample has an associated README file that provides the steps for using that sample. This file is located in the help system or in HyperText Markup Language (HTML) format on disk in the sample's folder. However, there are a few steps that must be taken for all samples. The following first two steps are common to all samples:
The next steps (debugging and running the sample) differ based on the type of sample you use. The following are the sample types:
Sample type
Description
Executables
Create .exe files and are complete applications that are used alone; for example, a complete controls application.
Class libraries and components
Create .dll files that are used through other applications, such as ArcMap or a controls application. Some examples of dynamic-link libraries (DLLs) are commands, tools, extensions, custom layers, custom renderers, and custom symbols.
When you are done using a sample's DLL, you can unregister it.
Visual Studio settings—The first time you start Visual Studio 2005, you are prompted to choose development settings. Choosing different settings changes the options displayed in Visual Studio. Unless specified, dialog boxes and menu commands discussed in this document are defined based on the general development settings in Visual Studio 2005 Professional Edition.
Opening solution files
In Windows Explorer, browse to the sample's location on disk. The location will be in <Your ArcGIS install location>/DeveloperKit/SamplesNET (Desktop or Engine folder or both) with the folder name in the README file. Open the C# or VB.NET version and double-click the solution file (.sln) to open in Visual Studio 2005. See the following screen shot:
In the installed developer help system, the sample's location is in the sample's README file at the bottom of the document.
If opening a sample downloaded from the ESRI Developer Network (EDN) Web site, the README files will be found where you saved the ZIP file.
Compiling samples
In the opened Visual Studio 2005 solution for the sample, choose Build Solution from the Build menu or press F6 to compile the sample.
Some samples can have code updates or edits you need to make, such as pointing the sample to data located on your machine. These steps are highlighted in the README's How to use section and should be completed before you compile.
Debugging samples
This step is optional, as samples do not require debugging. However, stepping through the code of the sample to see what it is doing can be beneficial. To view what is happening, set breakpoints in the opened Visual Studio 2005 project so that code execution stops. To set breakpoints, click the border in Visual Studio next to the line of code where you want a breakpoint placed. If you want to debug an EXE, you can at this point. If you want to debug a DLL, set up the external application to use for debugging. For more information, see Debugging DLLs.
Before starting a debugging session, make sure the active configuration is set to Debug. Start the project by choosing Start Debugging on the Debug menu or press F5. The application (the .exe or the external one that was set for the .dll) launches. Interact as directed by the How to use steps in the README and outlined in Running samples. As you hit the breakpoints that were set, focus switches back to Visual Studio.
Debugging DLLs
Since a DLL is used through another application, you must set up Visual Studio to use that application as the debugging start action if you want to debug the DLL code. Access the opened sample project in Visual Studio 2005. If there is a Properties entry in the Solution Explorer, double-click it. If not, click the Project menu and select <Project name> Properties. When the property pages open, click the Debug tab and, in the Start Action section, choose Start external program; be sure to choose Debug in the Configuration drop-down list.
Next, set the external program that you want to use. The README file helps you figure out which of the following options you should choose:
ArcGIS Desktop SDK—If the sample creates a DLL that only works with ArcMap, ArcCatalog, ArcGlobe, or ArcScene, set the external application to the ArcGIS application where the custom class is used. Browse to the location of the .exe for that application, located in <your ArcGIS install location>/Bin (for example, <your ArcGIS install location>/Bin/ArcMap.exe).
ArcGIS Engine SDK—If the sample creates a .dll that works in a controls application, browse to the location of the controls application to use. If you do not have one, refer to the help topics under the following nodes in the ArcGIS Engine SDK: Building solutions with ArcGIS Engine using .NET, Working with ArcGIS components, ArcGIS Engine controls.
If the sample is a command or tool that needs to be added to a toolbar linked to a MapControl, use the Allow run time customization of the ToolbarControl sample (only applies to ArcGIS Engine). This application lets you add the command at run time.
If you are working with a sample command or tool that can be added to ArcMap or a controls application, use the previous ArcGIS Desktop SDK or ArcGIS Engine SDK option, depending on the one you have installed.
If you are using Visual C# 2005 Express Edition or Visual Basic 2005 Express Edition, you cannot debug DLLs because these versions do not have the option to start an external application for debugging.
Running samples
Now that you have opened and compiled the sample, it is ready to use. Refer to the Additional Requirements and How to use sections of the sample's README file to see if you need to take additional steps before using the sample (adding specific data, starting an edit session, and so on).
Running EXEs
An executable sample can be used like any .exe on your machine by double-clicking the compiled .exe in Windows Explorer. Alternatively, you can run the .exe in debug mode as discussed in Debugging samples.
Running DLLs
If the sample produces a DLL, this indicates that the sample will provide custom classes to extend ArcGIS applications, such as a custom command. The sample's README file indicates the application—one of the ArcGIS applications or a custom one—the custom class should be used with. To use it, start the application and follow the README steps for using the sample.
DLLs need to be registered with the Component Object Model (COM) and can require registering classes to component categories. The sample code takes care of this registration, and the samples will be registered appropriately at compile time.
Adding commands or tools to a toolbar
Running a command or tool DLL involves adding it to a toolbar. The sample's README file indicates the kind of toolbar the command or tool works with and provides both the category the command or tool is in and the name of the command or tool. The following outlines the necessary steps to take based on the kind of toolbar the command or tool works with:
An ArcGIS Desktop application (ArcMap, ArcCatalog, ArcGlobe, or ArcScene):
Run the application the tool or command works with.
Click the Tools menu and choose Customize to open the Customize dialog box.
Click the Commands tab.
Click the command or tool in the Categories pane.
In the Commands pane, click the command or tool. Drag and drop the command or tool and place it on the toolbar.
An ArcGIS Engine controls application (on the ToolbarControl):
With the ArcGIS Engine controls applications—unless the toolbar is set up to allow customization at run time—you need to add the command or tool to the application at design time. To add it at design time, you have the following options:
Add the command or tool programmatically:
Once the ToolbarControl is created, initialized, and buddied, call AddItem on the ToolbarControl. See the following code example:
Dim sProgID AsString
sProgID ="esriControls.ControlsMapFullExtentCommand"
ToolbarControl1.AddItem sProgID
Add the command or tool through the ToolbarControl property pages:
In the design view of the application, right-click the ToolbarControl.
On the property page, click the Items tab, then click the Add button to open the Control Commands dialog box.
Click the command or tool category in the Categories pane.
In the Commands pane, click the command or tool. Double-click the command or tool, or drag and drop it on the toolbar on the Items tab of the property page.
If you are using an application that is set up to allow customization of the ToolbarControl at run time, follow that application's steps for adding a command or tool to the ToolbarControl.
The Allow run time customization of the ToolbarControl is a recommended sample that is used to test sample tools and commands (only applies to ArcGIS Engine). The sample needs to be placed on a ToolbarControl that is buddied with a MapControl. The following is the sample's location:
If you have not used this sample, choose the C# or VB.NET version of the sample and compile it, then browse to and launch the created .exe.
Click the Customize check box to open the Control Commands dialog box and click the Commands tab.
Choose the category the command is in from the Categories pane, click the command or tool from the Commands pane, then drag and drop it on the application's toolbar.
For one of the ArcGIS Desktop applications or a controls application—depending on what you have installed on your machine—follow the previous steps for ArcGIS Desktop or ArcGIS Engine.
Unregistering DLLs
You can unregister a DLL sample from your machine when you are done. To unregister a DLL, use the Assembly Registration Tool (regasm.exe) with the command line flag /unregister; for example, regasm MySample.dll/unregister.
Regasm.exe can be found in %windir%\Microsoft.NET\Framework\v2.0.xxxx (where xxxx is the build number of the .NET framework you are using).
On the taskbar, click Start and click Run. In the Run dialog box, type cmd to get a command prompt.