Hi all. I am new to using VB.NET to make a custom dll and have looked at lots of examples online. I found one that uses the hookhelper object to get to ArcGIS (from the IHookHelper interface). This seems to work fine but I want to be able to access the IMxDocument interface and these 2 objects don't seems to "query interface" together.I want this code to have a button on ArcMap that opens a form. The example code I found for this may be a little outdated but this is what I have so far for initializing it. Can anyone point me in the direction on how to get to the IMxDocument interface? Or maybe a new example code on custom dlls?Imports System.Runtime.InteropServices
Imports System.Drawing
'Imports ESRI.ArcGIS.ArcMapUI
'Imports ESRI.ArcGIS.Carto
'Imports ESRI.ArcGIS.Framework
'Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.Controls
''' <summary>
''' Summary description for VisualizationBtn.
''' </summary>
<ComClass(VisualizationBtn.ClassId, VisualizationBtn.InterfaceId, VisualizationBtn.EventsId)> _
Public NotInheritable Class VisualizationBtn
Inherits BaseCommand
Private m_hookHelper As IHookHelper
#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 = "670d215e-8631-40f1-a0f4-5cc6d52ce8fa"
Public Const InterfaceId As String = "8058e6e6-a106-40af-8d89-14b13c2aae8b"
Public Const EventsId As String = "4ce420bc-5909-4f6c-8a2f-913ecf2ea422"
#End Region
#Region "Component Category Registration"
'<ComRegisterFunction(), ComVisibleAttribute(False)> _
'Public Shared Sub RegisterFunction(ByVal regKey As String)
' MxCommands.Register(regKey)
'End Sub
'<ComUnregisterFunction(), ComVisibleAttribute(False)> _
'Public Shared Sub UnregisterFunction(ByVal regKey As String)
' MxCommands.Unregister(regKey)
'End Sub
#End Region
#Region "COM Registration Function(s)"
<ComRegisterFunction(), ComVisible(False)> _
Private Shared Sub RegisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType)
'
' TODO: Add any COM registration code here
'
End Sub
<ComUnregisterFunction(), ComVisible(False)> _
Private Shared Sub UnregisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType)
'
' TODO: Add any COM unregistration code here
'
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)
ControlsCommands.Register(regKey)
MxCommands.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)
ControlsCommands.Unregister(regKey)
MxCommands.Unregister(regKey)
End Sub
#End Region
#End Region
' 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()
MyBase.m_category = "VB.NET Visualization"
MyBase.m_caption = "VB.NET Visualization"
MyBase.m_message = "Display the visualization form"
MyBase.m_toolTip = "VB.NET Visualization"
MyBase.m_name = "Developer Samples_FullExtent VB.NET"
Try
Dim bitmapResourceName As String = Me.GetType().Name & ".bmp"
MyBase.m_bitmap = New Bitmap(Me.GetType(), bitmapResourceName)
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap")
End Try
End Sub
''' <summary>
''' Occurs when this command is created
''' </summary>
''' <param name="hook">Instance of the application</param>
Public Overrides Sub OnCreate(ByVal hook As Object)
If hook Is Nothing Then
Return
End If
If m_hookHelper Is Nothing Then
m_hookHelper = New HookHelperClass()
End If
m_hookHelper.Hook = hook
End Sub
''' <summary>
''' Occurs when this command is clicked
''' </summary>
Public Overrides Sub OnClick()
If Nothing Is m_hookHelper Then
Return
End If
If m_hookHelper.FocusMap.LayerCount > 0 Then
Dim visualizationFrm As VisualizationFrm = New VisualizationFrm(m_hookHelper) 'VisualizationFrm(m_hookHelper)
visualizationFrm.Show()
End If
End Sub
End Class
And the this is part of the code I have written when the form is opened:Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.Controls
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Public Class VisualizationFrm
Private m_pMxDoc As IMxDocument
Private m_pMap As IMap
Private m_pApp As IApplication
Private m_hookHelper As IHookHelper = Nothing
Public Sub New(ByVal hookHelper As IHookHelper)
InitializeComponent()
m_hookHelper = hookHelper
End Sub
End Class
Thanks!