Registration Code

503
3
11-03-2011 02:26 PM
GeorgeFaraj
Occasional Contributor III
This is a silly question that I hope someone can really answer: I have written an application that uses several (more than 20) custom commands and tools. They all work great but I noticed when I first started building them that they worked whether I included the following registration code or not - so I've left it out.  I have no intention of ever making any of these controls installable.  They exist solely for this program. Do I need this boilerplate or not?  Does anyone know the answer?

    
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
  // Required for ArcGIS Component Category Registrar support
  ArcGISCategoryRegistration(registerType);
  //
  // TODO: Add any COM registration code here
  //
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
  // Required for ArcGIS Component Category Registrar support
  ArcGISCategoryUnregistration(registerType);
  //
  // TODO: Add any COM unregistration code here
  //
}

/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
  string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
  ControlsCommands.Register(regKey);
}

/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
  string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
  ControlsCommands.Unregister(regKey);
}
#endregion
0 Kudos
3 Replies
NeilClemmons
Regular Contributor III
It depends on what you're doing.  The component categories exist so that ArcGIS can be made aware of the components they contain.  So, if you write a custom command/tool for ArcMap and you want it to go on a toolbar then you have to register it in the MxCommands component category.  However, if you wanted to execute that command from a button on a dialog (i.e. by creating a new instance of the command class and executing it via code) then it doesn't matter if it's registered in a component category or not.  The registration code you posted is for registering custom commands/tools for an ArcGIS Engine application.  If you want to put those commands/tools on the ESRI Toolbar Control then you will need to register them so that they are available for you to choose in the toolbar properties dialog.  If you're creating instances of the command/tool classes yourself via code and executing them or making them the current tool via code then you don't need to register them.
0 Kudos
GeorgeFaraj
Occasional Contributor III
If you want to put those commands/tools on the ESRI Toolbar Control then you will need to register them so that they are available for you to choose in the toolbar properties dialog.  If you're creating instances of the command/tool classes yourself via code and executing them or making them the current tool via code then you don't need to register them.


Forgive my imprecision! That is kind of the point of my post. My program is a standalone viewer that will never use any external tools or commands - everything is wired directly in code. I am creating classes for the commands and tools (for example MyOwnUsefulTool class) and using them on an ArcGIS Engine Toolbar control by:

toolsView.AddItem( new MyOwnUsefulTool( synchronizer ), 0, -1, false, 0, style ); 


They work fine without the registration code (as far as I can see.)  All the right places in the class are being called (OnCreate(), OnClick(), Enabled and so on.) Is there a hidden problem with doing this (memory leaks, null exceptions, COM errors, Demonic possession, or whatevah?)

I'll take the time to add them if they prevent problems but I'd rather not have the code if I don't need it. (I discovered by "mistake" that it worked without the code.)
0 Kudos
NeilClemmons
Regular Contributor III
You should be fine.  The registration code is only used to register the classes in the component categories.  The component categories are how ArcGIS discovers what components are available.  Since you're handling the creation of your classes and are putting them on the toolbar yourself you don't need to put them into the component categories.
0 Kudos