Select to view content in your preferred language

Error when calling IAoInitialize::Initialize

493
2
08-30-2010 07:53 AM
BobCave
Emerging Contributor
I am attempting to get a license using IAoInitialize::Initialize() with ArcGIS 10.  The call returns CO_E_APPSINGLEUSE (-2147221002 or 0x800401F6).  The computer has a single-use license for ArcEditor, and ArcMap, ArcCatalog, etc. are able to access the license. 

Here is the C++ code I am using:

bool GetALicense()
{
 if (!InitializeLicense(esriLicenseProductCodeEngine))
 {
  if (!InitializeLicense(esriLicenseProductCodeArcView))
  {
   if (!InitializeLicense(esriLicenseProductCodeArcEditor))
   {
    if (!InitializeLicense(esriLicenseProductCodeArcInfo))
    {
     wcout << "License Initialization failed" << endl; 
     return false;
    }
   }
  }
 }

 return true;
}

VARIANT_BOOL InitializeLicense(esriLicenseProductCode product)
{
 IAoInitializePtr ipInit(CLSID_AoInitialize);
 esriLicenseStatus licenseStatus = esriLicenseFailure;
 HRESULT hr = S_OK;

 hr = ipInit->Initialize(product, &licenseStatus);

 if (FAILED(hr))
 {
  wcout << "Initialize failed, hr=" << hr << endl;
 }

 return (licenseStatus == esriLicenseCheckedOut);
}



Every call to Initialize() returns the error.  This same code works on computers with ArcGIS 9.3 installed.

Has anyone else run into this?  Were there changes to licensing from ArcGIS 9.3 to ArcGIS 10?  The online samples use the same scheme to get a license, and my code is based on one of those samples.

Thanks,

Bob
0 Kudos
2 Replies
ScottKutz
Emerging Contributor
Bob,

  It seems that you may need to add code for the new "binding" requirement introduced at the ArcGIS 10.0 level.

  Briefly, in the C++ environment, ArcGIS 10.0 brings a new requirement for using the IArcGISVersion interface along with its ->LoadVersion() method to bind the application to a specific ArcGIS release level. You will likely also need to add a new #import statement to gain access to the associated ArcGISVersion.dll. A sample code fragment for use with an ArcEngine application is shown below. This binding code now needs to be executed between the call to "::AoInitialize" and the call to "ipInit->Initialize()".  
----------------------------
// New for ArcGIS 10.0
IArcGISVersionPtr ipVersion(CLSID_VersionManager);
VARIANT_BOOL succeeded;
hr = ipVersion->LoadVersion(esriArcGISEngine, L"10.0", &succeeded);
----------------------------

  Please see the following forum entry for a code sample, additional discussion, and a link to a new ArcGIS 10.0 Help topic that discusses the need to perform this runtime binding in C++.

http://forums.arcgis.com/threads/2893-Migrating-standalone-Visual-C-ArcGIS-Engine-applications-to-Ar...

  I hope this helps.

Scott
0 Kudos
BobCave
Emerging Contributor
Thanks, Scott.  I have a couple of additional questions, so I posted them on the other thread to try to keep the discussion in one place.
0 Kudos