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.

THE V ISUAL BASIC 6 DEVELOPMENT ENVIRONMENT<br />

DEBUGGING VISUAL BASIC CODE<br />

Visual Basic has a debugger integrated into its development environment. This is,<br />

in many cases, a valuable tool when debugging Visual Basic code; however, in<br />

some cases it is not possible to use the VB debugger. The use of the debugger and<br />

these special cases are discussed below.<br />

Running the code within an application<br />

It is possible to use the Visual Basic debugger to debug your ArcObjects softwarebased<br />

source code even when ActiveX DLLs are the target server. The application<br />

that will host your DLL must be set as the Debug application. To do this,<br />

select the appropriate application, ArcMap.exe, for instance, and set it as the Start<br />

Program in the Debugging options of the Project Properties.<br />

Using commands on the Debug toolbar, ArcMap can be started and the DLL<br />

loaded and debugged. Break points can be set, lines stepped over, functions<br />

stepped into, and variables checked. Moving the line pointer in the left margin<br />

can also set the current execution line.<br />

Visual Basic debugger issues<br />

In many cases, the Visual Basic debugger will work without any problems; however,<br />

there are two problems when using the debugger that is supplied with<br />

Visual Basic 6. Both of these problems exist because of the way that Visual Basic<br />

implements its debugger.<br />

Normally when running a tool within ArcMap, the DLL is loaded into ArcMap<br />

address space, and calls are made directly into the DLL. When debugging, this is<br />

not the case. Visual Basic makes changes to the registry so that the class identifier<br />

(CLSID) for your DLL does not point to your DLL but, instead, points to the<br />

Visual Basic Debug DLL (VB6debug.dll). The Debug DLL must then support all<br />

the interfaces implemented by your class on the fly. With the VB Debug DLL<br />

loaded into ArcMap, any method calls that come into the DLL are forwarded to<br />

Visual Basic, where the code to be debugged is executed. The two problems with<br />

this are caused by the changes made to the registry and the cross-process space<br />

method calling. When these restrictions are first encountered, it can be confusing<br />

since the object works outside the debugger or at least until it hits the area of<br />

problem code.<br />

Since the method calls made from ArcMap to the custom tool are across apartments,<br />

there is a requirement for the interfaces to be marshalled. This marshalling<br />

causes problems in certain circumstances. Most data types can be automatically<br />

marshalled by the system, but there are a few that require custom code because<br />

the standard marshaller does not support the data types. If one of these data<br />

types is used by an interface within the custom tool and there is no custom marshalling<br />

code, the debugger will fail with an “Interface not supported” error.<br />

The registry manipulation also breaks the support for component categories. Any<br />

time there is a request on a component category, the category manager within<br />

COM will be unable to find your component because, rather than asking whether<br />

your DLL belongs to the component category, COM is asking whether the VB<br />

96 • <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!