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.

.NET APPLICATION PROGRAMMING INTERFACE<br />

env.DefineFromPoints(3, ref pointArray);<br />

// Doesn't work<br />

env.DefineFromPoints(3, ref pointArray[0]);<br />

// Works<br />

envGEN.DefineFromPoints(ref pointArray);<br />

Class Interfaces<br />

Class interfaces are created to help VB programmers transition to .NET; they are<br />

also commonly used in code produced by the Visual Basic .NET Upgrade Wizard<br />

or the code snippet converter in Visual Studio .NET.<br />

However, it is generally recommended that you avoid using the class interfaces in<br />

the ESRI interop assemblies, as they may change in future versions of <strong>ArcGIS</strong>.<br />

This section explains a little more about class interfaces.<br />

In Visual Basic 6, the details of default interfaces were hidden from the user, and<br />

a programmer could instantiate a variable and access the members of its default<br />

interface without performing a specific QI for that interface; for example, the<br />

VB 6 code below instantiates the StdFont class and sets a variable equal to the<br />

default interface (IStdFont) of that class:<br />

[VB 6.0]<br />

Dim fnt As New Stdole.StdFont<br />

However, .NET does not provide this same ability. To allow VB developers a<br />

more seamless introduction to .NET, the type library importer in .NET adds ‘class<br />

interfaces’ to each interop assembly, allowing COM objects to be used with this<br />

same syntax inside .NET. When an object library is imported, a class interface<br />

RCW is created for each COM class; the name of the class interface is the same as<br />

the COM class—for example, Envelope.<br />

All the members of the default interface of the COM class are added to this class<br />

interface; also, if the COM class has a source interface (is the source of events),<br />

then the class interface will also include all the events of this interface, which<br />

helps a programmer to link up events.<br />

A second RCW is created that represents the underlying COM class; the name of<br />

this is the same as the COM class with a suffix of ‘Class’, for example,<br />

EnvelopeClass. The class interface is linked to the class by an attribute, which<br />

indicates the class to which it belongs. This attribute is recognized by the .NET<br />

compilers, which allows a programmer to instantiate a class by using its class<br />

interface.<br />

The exception is classes that have a default interface of IUnknown or IDispatch,<br />

which are never exposed on RCW classes as the members are called internally by<br />

the .NET Framework runtime. In this case, the next implemented interface is<br />

exposed on the class interface instead. As most ArcObjects define IUnknown as<br />

their default interface, this affects most ArcObjects classes. For example, the<br />

Point COM class in the esriGeometry object library lists the IPoint interface as its<br />

first implemented interface. In .NET, this class is accessed by using the Point class<br />

interface, which inherits the IPoint interface, and the PointClass class.<br />

The code below shows that by declaring a variable type as a Point class interface,<br />

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

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

Saved successfully!

Ooh no, something went wrong!