ArcGIS 10: Add-In (add Button to Menu 'File')

Discussion created by ganders on Apr 20, 2011
Latest reply on Apr 22, 2011 by jhauck-esristaff
Hi folks

i need to add some functionality to ArcMap's File-Menu. I'm using the code listet below to create the add-in and adding the button to the menu... well, clicking the menu 'file' causes ArcMap to crash. So obviously, there has to be an error.

any ideas?

<AddIn language="CLR" library="GeoServerData.dll" namespace="GeoServerData">
        <Button id="Stadt_Zürich_uidsample_Button1" class="Button1" message="Add-in command generated by Visual Studio project wizard." caption="My Button" tip="Add-in command tooltip." category="Add-In Controls" image="Images\Button1.png" />
        <Extension id="Stadt_Zürich_uidsample_Extension1" class="Extension1" productName="UIDSample" showInExtensionDialog="true" autoLoad="true" />

class Extension (inherits from ESRI.ArcGIS.Desktop.AddIns.Extension)
Protected Overrides Function OnSetState(ByVal state As ESRI.ArcGIS.Desktop.AddIns.ExtensionState) As Boolean
        If state = esriExtensionState.esriESEnabled Then
            ' Add OnNewDocument event handler.
            m_dNewDocEvent = New ESRI.ArcGIS.ArcMapUI.IDocumentEvents_NewDocumentEventHandler(AddressOf AddCommandToMenu)
            AddHandler CType(m_MxDoc, ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event).NewDocument, m_dNewDocEvent
            ' Add OnOpenDocument event handler.
            m_dOpenDocEvent = New ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(AddressOf AddCommandToMenu)
            AddHandler CType(m_MxDoc, ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event).OpenDocument, m_dOpenDocEvent
        End If
        Return MyBase.OnSetState(state)
    End Function

    Public Sub AddCommandToMenu()
            Dim pUID As New UID With {.Value = "{56599DD3-E464-11D1-9496-080009EEBECB}"}
            Dim pCmdItem As ICommandBar
            pCmdItem = application.Document.CommandBars.Find(pUID)

            Dim btnuid As New UID With {.Value = My.ThisAddIn.IDs.Button1}
        Catch ex As Exception
        End Try
    End Sub

class Button1:
Public Sub New()
        application = CType(Hook, IApplication)
    End Sub

    Protected Overrides Sub OnClick()
    End Sub

any help will be greatly appreciated!

best regards