Binding to ArcGIS Desktop in C++

3264
6
09-21-2011 10:00 AM
ErikaDade
New Contributor III
Hi all,

Can someone tell me how to bind a standalone C++ app to ArcGIS Desktop ?

I have put the following include in stdafx.h along with other esri libraries.

#import "C:/Program Files (x86)/Common Files/ArcGIS/bin/ArcGISVersion.dll" raw_interfaces_only raw_native_types no_namespace named_guids rename("esriProductCode","esriVersionProductCode" ) rename("VersionManager","esriVersionManager" )

And here is how I see others in forums binding to desktop in .NET:

'Add runtime management
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)

However, I cannot find a RuntimeManager class in the ArcGISVersion library to implement in C++.   Do you have to do this in Arc 10.0 before running AoInitialize?  If I just attempt to initialize using LicenseUtilities(.cpp), I get the error <no appropriate license available>

Do you need to have ArcEngine if you only want to bind to Desktop?

Thanks for your help!
0 Kudos
6 Replies
ErikaDade
New Contributor III
Stilll stuck.

Tried running the DevKit10.0/VCPP sample "Computing the Slope of a Raster Dataset".  Changed the VS2010 project to target .NET 4.0 for VS2010 (it was 3.5).  And changed product to bind to from esriArcGISEngine to esriArcGISDesktop.   The program runs successfully with Admin privileges (says slope has been calculated) except that there is no output raster dataset.

Does anyone know- do you need to bind to ArcGIS Engine to run standalone apps?

Thanks for your help!
0 Kudos
RichardWatson
Frequent Contributor
I think that binding to Desktop should be fine.  We do it.

BTW, ESRI doesn't support the 4.0 framework until 10.1.
0 Kudos
ErikaDade
New Contributor III
Thanks for that.  I have been building in VS 2010 against .NET 4.0 with no trouble for my other ArcGIS 10.0 projects (ignorance has been bliss so far, but I shall take heed now).   When in 2012 will ArcGIS 10.1 release?

I only have the express version of VS C++ 2008, which does not have ATL (or MFC) libraries, so I cannot build the sample project (RasterSlope2010.sln).    Has anyone else successfully run this VCPP sample (ie does it actually output the slope raster dataset)?
0 Kudos
UmbertoRaggiani
New Contributor III
I am also encountering difficulties with ArcGIS10.1 and C++.

here is how we initiated the code  (simplified)
VARIANT_BOOL vb; 
esriLicenseStatus licenseStatus = 0;

IArcGISVersionPtr ipVersion(__uuidof(VersionManager)); 
ipVersion->LoadVersion(esriArcGISServer, L"", &vb);
IAoInitializePtr ipInit(CLSID_AoInitialize); 
ipInit->IsProductCodeAvailable(product, &licenseStatus);
ipInit->Initialize(product, &licenseStatus);


The ClsId of AoInitialize was :0xe01be902,0xcc85,0x4b13,0xa8,0x28,0x02,0xe7,0x89,0xe0,0xdd,0xa9}};

The ClsId of VersionManager was :
a4092e33-e459-4b9c-b04e-263fb7a8e1d1 (IArcGISVersion)

..when I try this under the ArcGIS10.1 beta, it doesn't work anymore.

Does anyone have a basic C++ sample for ArcGIS10.1?
0 Kudos
UmbertoRaggiani
New Contributor III
keywords : ArcGIS10.1 Beta2 - C++ application sample validate the license.

You need to import ArcGISVersion.dll:
#import "\Program Files\Common Files\ArcGIS\bin\ArcGISVersion.dll" named_guids no_namespace raw_interfaces_only no_implementation rename("esriProductCode", "ProductCode")

The AutoDesktopLicense class inits the license for desktop.

class AutoLicense
{
public:
  AutoLicense()  {}
  ~AutoLicense() { if (m_ipAoi) m_ipAoi->Shutdown(); }
protected:
  IAoInitializePtr m_ipAoi;
};

class AutoDesktopLicense : AutoLicense
{
public:
  AutoDesktopLicense()
  {
    IArcGISVersionPtr ipVersion(CLSID_VersionManager);
    VARIANT_BOOL ok;
    HRESULT hr = ipVersion->LoadVersion(esriArcGISDesktop, _bstr_t(L"10.1"), &ok); 
    ASSERT(SUCCEEDED(hr) && ok == VARIANT_TRUE);
    if (FAILED(hr)) throw hr;

    esriLicenseStatus status;
    hr = m_ipAoi->Initialize(esriLicenseProductCodeStandard, &status);
    ASSERT(SUCCEEDED(hr));
    if (FAILED(hr)) throw hr;
  }
};

And it can be used like so:

  ::CoInitialize(0);

  {
    AutoServerLicense();

    //do the arcobjects thing here
  }

  ::CoUninitialize();
MattDenton
New Contributor II

Not that this is a current thread, but between Umberto Raggiani's #import statement and this response from Michael Rice‌, I got what I was doing working in a jiff.  Thanks guys!

0 Kudos