Frequently asked question

Are there C++ and .NET samples for using ASR licenses?

Last Published: April 25, 2020

Answer



** Internal Publish Only! This article may contain information that is not intended for external circulation. **



Yes. As follows:

C++ Samples:

stdafx.h

include <atlbase.h>
pragma warning(push)
pragma warning(disable : 4192) /* Ignore warnings for types that are duplicated in win32 header files */
pragma warning(disable : 4146) /* Ignore warnings for use of minus on unsigned types */
import "C:\\program files\\common files\\ArcGIS\\bin\\ArcGISVersion.dll" raw_interfaces_only raw_native_types named_guids
import "esriSystem.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_COLOR", "OLE_HANDLE", "VARTYPE")
import "AoAuthorizer.dll" raw_interfaces_only raw_native_types no_namespace named_guids
pragma warning(pop)

Authorize ASR From File:

include "stdafx.h"
int main(int argc, char *argv[]) {

CoInitialize(0);
{
// Must Bind to the correct ArcGIS version
ArcGISVersionLib::IArcGISVersionPtr ipVersion;
ipVersion.CreateInstance(ArcGISVersionLib::CLSID_VersionManager);
VARIANT_BOOL pass = VARIANT_FALSE;
// For Desktop, use ArcGISVersionLib::esriArcGISDesktop
ipVersion->LoadVersion(ArcGISVersionLib::esriArcGISEngine,
CComBSTR(L"10.0"), &pass);

IAuthorizeLicensePtr pAuth(CLSID_AoAuthorizeLicense);
HRESULT hResult = pAuth->AuthorizeASRFromFile
(_T("<path_to_asr>"), _T("<password>"));
BSTR featuresAdded;
hResult = pAuth->get_FeaturesAdded(&featuresAdded);
}
CoUninitialize();
return 0;
}

Deauthorize ASR:

include "stdafx.h"
int main(int argc, char *argv[]) {

CoInitialize(0);
{
// Must Bind to the correct ArcGIS version
ArcGISVersionLib::IArcGISVersionPtr ipVersion;
ipVersion.CreateInstance(ArcGISVersionLib::CLSID_VersionManager);
VARIANT_BOOL pass = VARIANT_FALSE;
// For Desktop, use ArcGISVersionLib::esriArcGISDesktop
ipVersion->LoadVersion(ArcGISVersionLib::esriArcGISEngine,
CComBSTR(L"10.0"), &pass);

IAuthorizeLicensePtr pAuth(CLSID_AoAuthorizeLicense);
BSTR strAsr = _T("<asr_string>") ;
BSTR strPassword = _T("<password>") ;
HRESULT hResult = pAuth->DeauthorizeASR(strAsr, strPassword);
}
CoUninitialize();
return 0;
}

Repair ASR From File:

include "stdafx.h"
int main(int argc, char *argv[]) {

CoInitialize(0);
{
// Must Bind to the correct ArcGIS version
ArcGISVersionLib::IArcGISVersionPtr ipVersion;
ipVersion.CreateInstance(ArcGISVersionLib::CLSID_VersionManager);
VARIANT_BOOL pass = VARIANT_FALSE;
// For Desktop, use ArcGISVersionLib::esriArcGISDesktop
ipVersion->LoadVersion(ArcGISVersionLib::esriArcGISEngine,
CComBSTR(L"10.0"), &pass);

IAuthorizeLicensePtr pAuth(CLSID_AoAuthorizeLicense);
HRESULT hResult = pAuth->CheckASRFromFile((_T("<path_to_asr>"),
_T("<password>"));

if (hResult != S_OK) // If check fails, get last error
{
BSTR error;
int errorCode; pAuth->get_LastError(&error, &errorCode); // Get error string and code

if (errorCode == -5) // ASR fulfillments are untrusted
{

hResult = pAuth->RepairASRFromFile
(_T("<path_to_asr>"), _T("<password>"));

BSTR featuresAdded;
hResult = pAuth->get_FeaturesAdded(&featuresAdded);
}

}
}
CoUninitialize();
return 0;
}
.NET Samples:

Authorize ASR From File: using System; using System.Text; using System.Runtime.InteropServices; using ESRI.ArcGIS.AoAuthorizer;

namespace SampleAuthorizeApp {

class Program
{
static void Main(string[] args)
{
// Set Runtime to Engine
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
// For Desktop, use ESRI.ArcGIS.ProductCode.Desktop
IAuthorizeLicense aoAuth = new AoAuthorizeLicenseClass();
try
{
aoAuth.AuthorizeASRFromFile("<path_to_asr>”, "<password>");

string features = aoAuth.FeaturesAdded;
}
catch (COMException ex)
{
string lastError;
int error = aoAuth.get_LastError(out lastError);
Console.Out.WriteLine(error + ": " + lastError);
}
}
}
}
Deauthorize ASR: using System; using System.Text; using System.Runtime.InteropServices; using ESRI.ArcGIS.AoAuthorizer;

namespace SampleAuthorizeApp {

class Program
{
static void Main(string[] args)
{
// Set Runtime to Engine
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
// For Desktop, use ESRI.ArcGIS.ProductCode.Desktop
IAuthorizeLicense aoAuth = new AoAuthorizeLicenseClass();
try
{
aoAuth.DeauthorizeASR("<asr_string>", "<password>");
}
catch (COMException ex)
{
string lastError;
int error = aoAuth.get_LastError(out lastError);
Console.Out.WriteLine(error + ": " + lastError);
}
}
}
}
Repair ASR From File: using System; using System.Text; using System.Runtime.InteropServices; using ESRI.ArcGIS.AoAuthorizer;

namespace SampleAuthorizeApp {

class Program
{
static void Main(string[] args)
{
// Set Runtime to Engine
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
// For Desktop, use ESRI.ArcGIS.ProductCode.Desktop
IAuthorizeLicense aoAuth = new AoAuthorizeLicenseClass();
try
{
aoAuth.CheckASRFromFile("<path_to_asr>", "<password>");
}
catch (COMException ex)
{
string lastError;
int error = aoAuth.get_LastError(out lastError);
if (error == -5) // ASR fulfillments are untrusted
{

aoAuth.RepairASRFromFile("<path_to_asr>", "<password>");
string features = aoAuth.FeaturesAdded;
}
}
}
}
} 

Article ID:000011428

Software:
  • ArcMap

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic