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

<strong>ArcGIS</strong> components<br />

Components that extend the <strong>ArcGIS</strong> applications are trickier to deploy than<br />

standalone applications because they must be registered with COM and in specific<br />

component categories. As discussed earlier, implementing COMRegisterFunction<br />

and COMUnregisterFunctions facilitates deployment by providing self category<br />

registration, but this only occurs when the components are registered.<br />

There are two techniques for registering components with COM. One option is to<br />

run the register assembly utility (RegAsm.exe) that ships with the .NET Framework<br />

SDK. This is typically not a viable solution as client machines may or may<br />

not have this utility and it’s difficult to automate. The second and recommended<br />

approach is to add an automatic registration step to a custom setup or install<br />

program.<br />

The key to creating a custom install program that both deploys and registers<br />

components is the System.Runtime.InteropServices.RegistrationServices class. This class<br />

has the members RegisterAssembly and UnregisterAssembly, which register and<br />

unregister managed classes with COM. These are the same functions the RegAsm<br />

utility uses. Using these functions inside a custom installer class along with a<br />

setup program is the complete solution.<br />

The basic steps below outline the creation of a deployable solution. NOTE: The<br />

steps assume you are starting with a solution that already contains a project with<br />

at least one COM-enabled class.<br />

1. In Visual Studio .NET, add a new Installer Class and name it accordingly.<br />

Override the Install and Uninstall functions that are implemented in the<br />

Installer base class and use the RegistrationServices class’s RegisterAssembly and<br />

UnregisterAssembly methods to register the components. Make sure you use the<br />

SetCodeBase flag; this indicates that the code base key for the assembly should<br />

be set in the registry.<br />

[VB.NET]<br />

Public Overrides Sub Install(ByVal stateSaver As<br />

System.Collections.IDictionary)<br />

MyBase.Install(stateSaver)<br />

Dim regsrv As New RegistrationServices<br />

regsrv.RegisterAssembly(MyBase.GetType().Assembly,<br />

AssemblyRegistrationFlags.SetCodeBase)<br />

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

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

Saved successfully!

Ooh no, something went wrong!