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.

THE V ISUAL BASIC 6 DEVELOPMENT ENVIRONMENT<br />

The previous section of this chapter focused primarily on how to write code in<br />

the VBA development environment embedded within the <strong>ArcGIS</strong> Desktop<br />

applications. This section focuses on particular issues related to creating ActiveX<br />

DLLs that can be added to the applications and writing external standalone<br />

applications using the Visual Basic development environment.<br />

The ESRI VB Add-In interface implementer can<br />

be used to automate Steps 3 and 4.<br />

CREATING COM COMPONENTS<br />

Most developers use Visual Basic to create a COM component that works with<br />

ArcMap or ArcCatalog. Earlier in this chapter you learned that since the ESRI<br />

applications are COM clients—their architecture supports the use of software<br />

components that adhere to the COM specification—you can build components<br />

with different languages including Visual Basic. These components can then be<br />

added to the applications easily. For information about packaging and deploying<br />

COM components that you’ve built with Visual Basic, see Chapter 5, ‘Licensing<br />

and deployment’, in this guide.<br />

This section is not intended as a Visual Basic tutorial; rather, it highlights aspects<br />

of Visual Basic that you should know to be effective when working with<br />

ArcObjects.<br />

In Visual Basic you can build a COM component that will work with ArcMap or<br />

ArcCatalog by creating an ActiveX DLL. This section will review the rudimentary<br />

steps involved. Note that these steps are not all-inclusive. Your project may<br />

involve other requirements.<br />

1. Start Visual Basic. In the New Project dialog box, create an ActiveX DLL<br />

Project.<br />

2. In the Properties window, make sure that the Instancing property for the<br />

initial class module and any other class modules you add to the Project are set<br />

to 5—MultiUse.<br />

3. Reference the ESRI object libraries that you will require.<br />

4. Implement the required interfaces. When you implement an interface in a class<br />

module, the class provides its own versions of all the public procedures specified<br />

in the type library of the interface. In addition to providing mapping<br />

between the interface prototypes and your procedures, the Implements statement<br />

causes the class to accept COM QueryInterface calls for the specified<br />

interface ID. You must include all the public procedures involved. A missing<br />

member in an implementation of an interface or class causes an error. If you<br />

don’t put code in one of the procedures in a class you are implementing, you<br />

can raise the appropriate error (Const E_NOTIMPL = &H80004001). That<br />

way, if someone else uses the class, they’ll understand that a member is not<br />

implemented.<br />

5. Add any code that’s needed.<br />

6. Establish the Project Name and other properties to identify the component. In<br />

the Project Properties dialog box, the project name you specify will be used as<br />

the name of the component’s type library. It can be combined with the name<br />

of each class the component provides to produce unique class names (these<br />

names are also called ProgIDs). These names appear in the Component Category<br />

Manager. Save the project.<br />

92 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!