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 />

Visual Basic automatically generates the<br />

necessary GUIDs for the classes, interfaces, and<br />

libraries. Setting binary compatibility forces VB to<br />

reuse the GUIDs from a previous compilation of<br />

the DLL. This is essential, since ArcMap stores<br />

the GUIDs of commands in the document for<br />

subsequent loading.<br />

7. Compile the DLL.<br />

8. Set the component’s Version Compatibility to binary. As your code evolves, it’s<br />

good practice to set the components to Binary Compatibility so, if you make<br />

changes to a component, you’ll be warned that you’re breaking compatibility.<br />

For additional information, see the ‘Binary compatibility mode’ help topic in<br />

the Visual Basic online help.<br />

9. Save the project.<br />

10. Make the component available to the application. You can add a component<br />

to a document or template by clicking the Add from file button in the Customize<br />

dialog box’s Commands tab. In addition, you can register a component<br />

in the Component Category Manager.<br />

IMPLEMENTING INTERFACES<br />

You implement interfaces differently in Visual Basic, depending on whether they<br />

are inbound or outbound interfaces. An outbound interface is seen by Visual<br />

Basic as an event source and is supported through the WithEvents keyword. To<br />

handle the outbound interface, IActiveViewEvents, in Visual Basic (the default<br />

outbound interface of the Map class), use the WithEvents keyword and provide<br />

appropriate functions to handle the events.<br />

Private WithEvents ViewEvents As Map<br />

Private Sub ViewEvents_SelectionChanged()<br />

' User changed feature selection update my feature list form<br />

UpdateMyFeatureForm<br />

End Sub<br />

Inbound interfaces are supported with the Implements keyword. However, unlike<br />

the outbound interface, all the methods defined on the interface must be stubbed<br />

out. This ensures that the vTable is correctly formed when the object is instantiated.<br />

Not all the methods have to be fully coded, but the stub functions must be<br />

there. If the implementation is blank, an appropriate return code should be given<br />

to any client to inform them that the method is not implemented (see the section<br />

‘Working with HRESULTs’ in this chapter). To implement the IExtension interface,<br />

code similar to that below is required. Note that all the methods are implemented.<br />

Private m_pApp As IApplication<br />

Implements IExtension<br />

Private Property Get IExtension_Name() As String<br />

IExtension_Name = "Sample Extension"<br />

End Property<br />

Private Sub IExtension_Startup(ByRef initializationData As Variant)<br />

Set m_pApp = initializationData<br />

End Sub<br />

Private Sub IExtension_Shutdown()<br />

Set m_pApp = Nothing<br />

End Sub<br />

Chapter 4 • <strong>Developer</strong> environments • 93

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

Saved successfully!

Ooh no, something went wrong!