Here's the VB.NET code for my extension
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.esriSystem
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.Framework
<ComClass(Extension.ClassId, Extension.InterfaceId, Extension.EventsId), _
ProgId("HabitatDigitizer_92.Extension")> _
Public Class Extension
Implements IExtension
Implements IExtensionConfig
Implements IPersistVariant
#Region "COM Registration Function(s)"
<ComRegisterFunction(), ComVisibleAttribute(False)> _
Public Shared Sub RegisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType)
'Add any COM registration code after the ArcGISCategoryRegistration() call
End Sub
<ComUnregisterFunction(), ComVisibleAttribute(False)> _
Public Shared Sub UnregisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType)
'Add any COM unregistration code after the ArcGISCategoryUnregistration() call
End Sub
#Region "ArcGIS Component Category Registrar generated code"
''' <summary>
''' Required method for ArcGIS Component Category registration -
''' Do not modify the contents of this method with the code editor.
''' </summary>
Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type)
Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
MxExtension.Register(regKey)
End Sub
''' <summary>
''' Required method for ArcGIS Component Category unregistration -
''' Do not modify the contents of this method with the code editor.
''' </summary>
Private Shared Sub ArcGISCategoryUnregistration(ByVal registerType As Type)
Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
MxExtension.Unregister(regKey)
End Sub
#End Region
#End Region
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "85653ca9-ea9e-4c4a-894c-3a263c12e509"
Public Const InterfaceId As String = "4326fdc0-a7bb-4f21-8f0b-f03d0caec6c0"
Public Const EventsId As String = "940f2b66-d7b2-44bb-9025-4a1c380c98aa"
#End Region
Private m_application As IApplication
Private m_enableState As esriExtensionState
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
''' <summary>
''' Determine extension state
''' </summary>
Private Function StateCheck(ByVal requestEnable As Boolean) As esriExtensionState
'TODO: Replace with advanced extension state checking if needed
'Turn on or off extension directly
If requestEnable Then
Return esriExtensionState.esriESEnabled
Else
Return esriExtensionState.esriESDisabled
End If
End Function
#Region "IExtension Members"
''' <summary>
''' Name of extension. Do not exceed 31 characters
''' </summary>
Public ReadOnly Property Name() As String Implements ESRI.ArcGIS.esriSystem.IExtension.Name
Get
Return "Habitat Digitizer Extension"
End Get
End Property
Public Sub Shutdown() Implements ESRI.ArcGIS.esriSystem.IExtension.Shutdown
'TODO: Clean up resources
m_application = Nothing
End Sub
Public Sub Startup(ByRef initializationData As Object) Implements ESRI.ArcGIS.esriSystem.IExtension.Startup
m_application = CType(initializationData, IApplication)
If m_application Is Nothing Then Return
'TODO: Add code to initialize the extension
End Sub
#End Region
#Region "IExtensionConfig Members"
Public ReadOnly Property Description() As String Implements ESRI.ArcGIS.esriSystem.IExtensionConfig.Description
Get
'TODO: Replace description (use \r\n for line break)
Return "Habitat Digitizer 5.0" & vbCrLf & "NOAA/NOS/NCCOS/CCMA/Biogeography Program" & vbCrLf & vbCrLf & "Provides tools to simplify the digitizing attribution process."
End Get
End Property
''' <summary>
''' Friendly name shown in the Extensions dialog
''' </summary>
Public ReadOnly Property ProductName() As String Implements ESRI.ArcGIS.esriSystem.IExtensionConfig.ProductName
Get
'TODO:Replace()
Return "Habitat Digitizer Extension"
End Get
End Property
Public Property State() As ESRI.ArcGIS.esriSystem.esriExtensionState Implements ESRI.ArcGIS.esriSystem.IExtensionConfig.State
Get
Return m_enableState
End Get
Set(ByVal value As ESRI.ArcGIS.esriSystem.esriExtensionState)
'If m_enableState <> 0 Or value = m_enableState Then Exit Property
If value = m_enableState Then Exit Property
'Check if ok to enable or disable extension
Dim requestState As esriExtensionState = value
If requestState = esriExtensionState.esriESEnabled Then
'Cannot enable if it's already in unavailable state
If m_enableState = esriExtensionState.esriESUnavailable Then
Throw New COMException("Cannot enable extension")
End If
'Determine if state can be changed
Dim checkState As esriExtensionState = StateCheck(True)
m_enableState = checkState
ElseIf requestState = esriExtensionState.esriESDisabled Then
'Determine if state can be changed
Dim checkState As esriExtensionState = StateCheck(False)
If (m_enableState <> checkState) Then m_enableState = checkState
End If
End Set
End Property
#End Region
#Region "IPersistVariant Members"
Public ReadOnly Property ID() As ESRI.ArcGIS.esriSystem.UID Implements ESRI.ArcGIS.esriSystem.IPersistVariant.ID
Get
Dim typeID As UID = New UIDClass()
typeID.Value = Me.GetType().GUID.ToString("B")
Return typeID
End Get
End Property
Public Sub Load(ByVal Stream As ESRI.ArcGIS.esriSystem.IVariantStream) Implements ESRI.ArcGIS.esriSystem.IPersistVariant.Load
'TODO: Load persisted data from document stream
Dim HDXTest As String
Dim Count As Integer
Dim Key As Object
Dim ItemList() As Object
Dim ListCount As Integer
Try
HDXTest = Stream.Read
While Not HDXTest Is Nothing
If HDXTest <> "HDX Stream" Then
System.Windows.Forms.MessageBox.Show("The classification scheme and settings in this project cannot be read and must be reloaded manually.", "Cannot load settings", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation)
Exit Sub
Else
Exit While
End If
HDXTest = Stream.Read
End While
Count = Stream.Read
If Not theDict Is Nothing Then If theDict.ContainsKey("HDX.Classification Name") Then theDict.Clear()
For i As Integer = 1 To Count
Key = Stream.Read
ListCount = Stream.Read
ReDim ItemList(ListCount)
For j As Integer = 0 To ListCount
ItemList(j) = Stream.Read
Next
theDict.Add(Key, ItemList)
Next
'If Count > 0 Then createrenderer()
Catch ex As Exception
ExceptionMessage(ex, "Extension: IPersist_Load")
End Try
Marshal.ReleaseComObject(Stream)
End Sub
Public Sub Save(ByVal Stream As ESRI.ArcGIS.esriSystem.IVariantStream) Implements ESRI.ArcGIS.esriSystem.IPersistVariant.Save
'TODO: Save extension related data to document stream
Dim Count As Integer
Dim ItemList() As Object
Try
Count = theDict.Count
If theDict.ContainsKey("HDX.Point Legend") Then Count -= 1
If theDict.ContainsKey("HDX.Line Legend") Then Count -= 1
If theDict.ContainsKey("HDX.Polygon Legend") Then Count -= 1
Stream.Write("HDX Stream")
Stream.Write(Count)
For Each Key As Object In theDict.Keys
If InStr(Key, "Legend") = 0 Then
ItemList = theDict.Item(Key)
Stream.Write(Key)
Count = ItemList.GetUpperBound(0)
Stream.Write(Count)
For i As Integer = 0 To Count
Stream.Write(ItemList(i))
Next
End If
Next
Catch ex As Exception
ExceptionMessage(ex, "Extension: IPersist_Save")
End Try
Marshal.ReleaseComObject(Stream)
End Sub
#End Region
End Class