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

make use of their functionality. For example, all ArcMap commands and tools<br />

must be registered in the ESRI Mx Commands component category. There are a<br />

few different ways you can register a .NET component in a particular category,<br />

but before doing so, the .NET components must be registered with COM. See the<br />

‘Registering .NET components with COM’ section above for details.<br />

Customize dialog box<br />

Custom .NET <strong>ArcGIS</strong> commands and tools can quickly be added to toolbars via<br />

the Add From File button on the Customize dialog box. In this case, you simply<br />

have to browse for the TLB and open it. The <strong>ArcGIS</strong> framework will automatically<br />

add the classes you select in the type library to the appropriate component<br />

category.<br />

Categories utility<br />

Another option is to use the Component Categories Manager (Categories.exe). In<br />

this case you select the desired component category in the utility, browse for your<br />

type library, and choose the appropriate class.<br />

COM Register Function<br />

The final and recommended solution is to add code to your .NET classes that will<br />

automatically register them in a particular component category whenever the<br />

component is registered with COM. The .NET Framework contains two attribute<br />

classes (ComRegisterFunctionAttribute and ComUnregisterFunctionAttribute)<br />

that allow you to specify methods that will be called whenever your component<br />

is being registered or unregistered. Both methods are passed the CLSID of the<br />

class currently being registered, and with this information you can write code<br />

inside the methods to make the appropriate registry entries or deletions. Registering<br />

a component in a component category requires that you also know the component<br />

category’s unique ID (CATID).<br />

The code excerpt below shows a custom ArcMap command that automatically<br />

registers itself in the MxCommands component category whenever the .NET<br />

assembly in which it resides is registered with COM.<br />

public sealed class AngleAngleTool: BaseTool<br />

{<br />

[ComRegisterFunction()]<br />

static void Reg(String regKey)<br />

{<br />

Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(regKey.<br />

Substring(18)+ "\\Implemented Categories\\" + "{B56A7C42-83D4-11D2-A2E9-<br />

080009B6F22B}");<br />

}<br />

[ComUnregisterFunction()]<br />

static void Unreg(String regKey)<br />

{<br />

Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(regKey.Substring(18)+<br />

"\\Implemented Categories\\" + "{B56A7C42-83D4-11D2-A2E9-080009B6F22B}");<br />

}<br />

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

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

Saved successfully!

Ooh no, something went wrong!