How do I check out a Spatial Analyst licence with ArcGIS 10 from VB6?

922
5
08-03-2011 06:52 AM
JonathanHandley
New Contributor
We have an ArcGIS extension written in VB6 (I know VB6 is not supported by ESRI - please read on). This calls Spatial Analyst functionality and therefore must check out a Spatial Analyst licence. Over the years ESRI have changed what was required to achieve this, but our last version of the extension was working ok. We have tested this on ArcMap 10 and it works. There is one curious thing though, the test for a Spatial Analyst licence returns False but we try to grab an object anyway and we???ve found this works all the time. It even works when the user has not loaded the Spatial Analyst licence or the Spatial Analyst toolbar in ArcMap (there is a Spatial Analyst licence available of course), so one assumes the code is managing to get a reference to Spatial Analyst somehow.
We have the same code in a VB6 standalone exe, which attempts a similar thing to the ArcGIS extension. The same code tries to check out a Spatial Analyst licence, it returns False, we try to carry on anyway (as in the extension) and then get the error:
-2147221002, ArcGIS product not specified.  You must first bind to an ArcGIS version prior to using any ArcGIS components.

Can anyone give me some example code of how to check out a Spatial Analyst licence from VB6 that works in a standalone VB6 executable? Or is it now impossible (seems unlikely).

Many thanks
Jonathan
0 Kudos
5 Replies
ChrisJohnson5
New Contributor
I'm also struggling with the same issue, we have a number of standalone VB6 exes calling Spatial Analyst.  Some of these will, in time, be converted to .NET, but in the short term we don't have the resources to convert all of these, so we're relying on a VB6 solution.  If you do find the solution, could you please post your solution on here.

There are a couple of existing threads on here that touch on this topic and might be useful, but I haven't found a solution.

In post #11 (http://forums.arcgis.com/threads/19857-ArcGIS-10-VB6-compatibility-DocumentEvents), fablesano suggests that we could use VersionManager to "replicate what in .NET world is done with RuntimeManager", but I don't know how I could replicate the BindLicense functionality.

In post #49 (http://forums.arcgis.com/threads/97-Beta-10-Custom-extensions), Thom York's post is interesting but I don't think this will help with Spatial Analyst.

Cheers,
      Chris
0 Kudos
PhilBlondin
New Contributor III
try the runtime manager.

If Not RuntimeManager.Bind(ProductCode.Desktop) then
msgbox "Did not find Arc license"
End If

I think you need a refernce to ESRI.ArcGIS.Version
I'm going off memory so I may be wrong.

I believe this is what you have to do now at version 10, is to check for a license when using a standalone app
0 Kudos
ChrisJohnson5
New Contributor
Thanks Al.

Is it possible to use the runtime manager from VB6, i.e. is there a COM equivalent to ESRI.ArcGIS.Version ?
0 Kudos
ChrisJohnson5
New Contributor
We've got a bit closer when creating our standalone VB6 exe

We created a .NET COMClass dll with a single function with a single line of code, using AlBowe's solution:

Return ESRI.ArcGIS.RuntimeManager.Bind(ProductCode)

Using RegAsm.exe we were able to create a .tlb file, which could be referenced by the VB6 project. Calling this function before calling pAoInitialize.Initialize seems to work, although we've a few more issues later in the code to deal with before we can get the whole project working.

In response to the original post: As mentioned before, this fix seems to work for a standalone VB6 exe, but not sure if it will be any use for your ArcGIS extension. I'm not even sure you will need to check out the licence at all for the extension, but I'm sure somebody here will have a definitive answer.
0 Kudos
JohnAnderson1
New Contributor III
This thread really saved my bacon today. I was trying to get an old standalone exe VB6 ArcObjects program to run under ArcGIS 10 and experienced the problem with license binding. This is legacy code which will be deprecated in 12 months, so we needed a quick fix. tooniron's method of creating a COM Interop class in .NET worked for me too.

If you need information on creating COM Interop classes in .NET, the following link may help for VB.NET. It is written for an older version of Visual Studio, but should still makes sense.

http://support.microsoft.com/kb/817248
0 Kudos