Developing an application in VB.NET some technical difficulties occurred.
Aim of the application is to add an existing *.lyr file to ArcMap using a VB.NET application and a DLL integrated in ArcMap.
Using the VB.NET application to initiate the DLL integrated in ArcMap an error occurred and ArcMap will shut down.
The source code used is listened below:
Public Sub AddLayerToActiveView(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal layerPathFile As System.String)
If activeView Is Nothing OrElse layerPathFile Is Nothing OrElse (Not layerPathFile.EndsWith(".lyr")) Then
Return
End If
' Create a new GxLayer
Dim gxLayer As ESRI.ArcGIS.Catalog.IGxLayer = New ESRI.ArcGIS.Catalog.GxLayerClass
Dim gxFile As ESRI.ArcGIS.Catalog.IGxFile = CType(gxLayer, ESRI.ArcGIS.Catalog.IGxFile) 'Explicit Cast
' Set the path for where the layerfile is located on disk
gxFile.Path = layerPathFile
' Test if we have a valid layer and add it to the map
If Not (gxLayer.Layer Is Nothing) Then
Dim map As ESRI.ArcGIS.Carto.IMap = activeView.FocusMap
gxLayer.Layer.Name = layerPathFile
map.AddLayer(gxLayer.Layer)
End If
End Sub
''' Aufruf AddLayerToActiveView mit Parametern
Dim myactiveView As IActiveView = GetActiveViewFromArcMap(My.ArcMap.Application)
Call AddLayerToActiveView(myactiveView, "M:\test\XY200.lyr")
''''
''' Funktion zur Rückgabe von ActiveView
Public Function GetActiveViewFromArcMap(ByVal application As ESRI.ArcGIS.Framework.IApplication) As ESRI.ArcGIS.Carto.IActiveView
If application Is Nothing Then
Return Nothing
End If
Dim mxDocument As ESRI.ArcGIS.ArcMapUI.IMxDocument = TryCast(application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument) ' Dynamic Cast
Dim activeView As ESRI.ArcGIS.Carto.IActiveView = mxDocument.ActiveView
Return activeView
End Function
Is it possible to initiate a DLL integrated in ArcMap by a standalone-application?
Any help would be appreciated.
Thank you