Select to view content in your preferred language

ArcGIS 10 VB6 compatibility - DocumentEvents

1856
10
12-21-2010 05:56 AM
FedericoAlbesano
Emerging Contributor
Hi,

even if a know VB6 is no more supported on ArcGIS 10 as a development tool, it has also been said that applications written in VB6 for earlier versions of ArcGIS (read 9.3.1) are expected to run on version 10 (http://events.esri.com/uc/QandA/index.cfm?fuseaction=answer&conferenceId=2F6DC1A1-1422-2418-883C3868...).

We have a VB6 ArcMap extension and for now we cannot afford migrating all that code to VB.NET.
I thing we're not alone in this kind of situation.
So we are now trying to make that extension work on ArcGIS 10.
We needed to hook some document events, so we put this code:


Private WithEvents m_DocEvt As DocumentEvents    

Private Sub IExtension_Startup(ByRef initializationData As Variant)
  On Error GoTo ErrorHandler
  
  Set objApplication = initializationData
    
  Exit Sub
ErrorHandler:
  MsgBoxShow "IExtension_Startup: " & Err.Number & " " & Err.Source & " " & Err.Description, vbCritical
End Sub

Private Property Let IExtensionConfig_State(ByVal ExtensionState As esriSystem.esriExtensionState)
  On Error GoTo ErrorHandler
  
  If ExtensionState <> m_extState Then
    'Activate
    If ExtensionState = esriESEnabled Then
      If InitializeExtension Then            'Our stuff  
        Set m_DocEvt = objApplication.Document   'Hook events (*) 
      Else
        ExtensionState = esriESUnavailable       
      End If
    ElseIf ExtensionState = esriESDisabled Then 
      Set m_DocEvt = Nothing
      StopExtension True                     'Our stuff                 
    End If
    m_extState = ExtensionState
  End If
  
  Exit Property
ErrorHandler:
  MsgBoxShow "IExtensionConfig_State LET: " & Err.Number & " " & Err.Source & " " & Err.Description, vbCritical
End Property


In ArcGIS 10, if we hook DocumentEvents in (*), when the first event is fired (NewDocument, OpenDocument, CloseDocument), even without writing any code in events procedure, ArcMap exits with AV ("ArcGIS Desktop has encountered a serious application error....")

Is someone experiencing this same problem?
Maybe ESRI forgot to update this class (DocumentEvents) that is specific for VB6? But what about VBA code?

Thanks in advance
Federico Albesano
0 Kudos
10 Replies
FedericoAlbesano
Emerging Contributor
In 9.3, you had to add a License Control to your form and you could right-click and go to properties and check the types of Product licenses you wanted your app to work with(ArcGIS Engine, ArcGIS Engine Enterprise GeoDatabase, ArcView, ArcEditor and ArcInfo).  When your app ran, it would automatically pick the correct license.  Since I now would have to pass productCode to pVer.LoadVersion, can I call pVer.LoadVersion multiple times passing it different productCodes to get the same effect?  Or do I have to try and determine the correct productCode license through code to use or maybe have the user select what license they have in order to apply the correct one?


In ArcGIS 10 you have to bind to a product version and then initialize a product license with LicenseControl or AoInitialize. Once binded to a product version, the binding cannot be revoked or changed while the application is still running. With IArcGISVersion you can list available products (take a look at it in VB6 with Object Viewer).
In fact I think you can bind to Engine runtime and then initialize ArcView or ArcInfo as license level (but you always need Engine runtime installed).
If you can take a look at class RuntimeManager in SDK for .NET (http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/RuntimeManager_Class/004...) you can see the following example for method Bind (VB.NET):

If Not ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine) Then
  If Not ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop) Then
    MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.")
    e.Cancel = True 'Abort application start up
  End If
End If


There is also a method BindLicense that bind to a product and initialize e license in one single call. I think .NET class RuntimeManager is built on top of VersionManager.
In VB6 you need to use the (undocumented) last one and try to replicate what in .NET world is done with RuntimeManager.
0 Kudos