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

code. COM is one example of unmanaged code. The .NET Framework interacts<br />

with COM via a technology known as COM Interop.<br />

For COM Interop to work, the Common Language Runtime (CLR) requires<br />

metadata for all the COM types. This means that the COM type definitions<br />

normally stored in the type libraries need to be converted to .NET metadata. This<br />

is easily accomplished with the Type Library Importer utility (tlbimp.exe), which<br />

ships with the .NET Framework SDK. This utility generates interop assemblies<br />

containing the metadata for all the COM definitions in a type library. Once<br />

metadata is available, .NET clients can seamlessly create instances of COM types<br />

and call its methods as though they were native .NET instances.<br />

The <strong>ArcGIS</strong> installation program also installs the<br />

Microsoft Stdole.dll PIA, providing interop for<br />

OLE font and picture classes, which are used by<br />

some ESRI libraries.<br />

Primary interop assemblies<br />

Primary interop assemblies (PIAs) are the official, vendor-supplied, .NET type<br />

definitions for interoperating with underlying COM types. Primary interop assemblies<br />

are strongly named by the COM library publisher to guarantee uniqueness.<br />

ESRI provides primary interop assemblies for all the ArcObjects type libraries<br />

that are implemented with COM. <strong>ArcGIS</strong> .NET developers should only use those<br />

primary interop assemblies that are installed in the Global Assembly Cache (GAC)<br />

during install if version 1.1 of the .NET Framework is detected. ESRI only<br />

supports the interop assemblies that ship with <strong>ArcGIS</strong>. You can identify a valid<br />

ESRI assembly by its public key (8FC3CC631E44AD86).<br />

COM wrappers<br />

The .NET runtime provides wrapper classes to make both managed and<br />

unmanaged clients believe<br />

they are communicating<br />

with objects within their<br />

respective environment.<br />

When managed clients call<br />

a method on a COM<br />

object, the runtime creates<br />

a runtime callable wrapper<br />

(RCW) that handles the<br />

marshalling between the<br />

two environments. Similarly,<br />

the .NET runtime<br />

creates COM-callable<br />

wrappers for the reverse case, COM clients communicating with .NET components.<br />

The illustration above outlines this process.<br />

Exposing .NET components to COM<br />

When creating .NET components that COM clients will make use of, follow the<br />

guidelines listed below to ensure interoperability.<br />

• Avoid using parameterized constructors.<br />

• Avoid using static methods.<br />

• Define event source interfaces in managed code.<br />

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