看到的关于如何解决ArcEngine license 许可证的问题

第一个出处-----“http://topic.csdn.net/u/20091114/19/ee120ce9-be9e-4835-b42c-bc494eec2c8e.html?seed=148945424&r=72264100#r_72264100”

第二个出处-------“http://www.cnblogs.com/gisoracle/archive/2010/12/21/1913216.html”

ArcGIS Engine产品开发中的许可文件初始化ArcGIS Engine developer kit产品以及相应的产品许可安装以后,只是为你的应用程序实现许可允许的功能提供了可能性,要想真的使得你的应用程序拥有这些功能,你还需要做一个许可文件的初始化工作。
注意:如果不做这个初始化工作,你有可能会在实现某些功能时碰到你没有相应的许可的提示。
这个许可文件的初试化工作需要在你的应用程序的入口处实现。下面是c#的初始化的代码示例

using ESRI.ArcGIS.esriSystem;

namespace LicenseInitializer
{
public class LicenseInitializer
{
private IAoInitialize m_AoInitialize = new AoInitializeClass();

public bool InitializeApplication()
{
bool bInitialized = true;

if (m_AoInitialize == null)
{
System.Windows.Forms.MessageBox.Show("Unable to initialize. This application cannot run!");
bInitialized = false;
}

//初始化应用程序
esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;

licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngine);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcView);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
System.Windows.Forms.MessageBox.Show(LicenseMessage(licenseStatus));
bInitialized = false;
}
}
}
}

return bInitialized;
}

public void ShutdownApplication()
{
if (m_AoInitialize == null) return;

//关闭 AoInitilaize对象
m_AoInitialize.Shutdown();
m_AoInitialize = null;
}

private esriLicenseStatus CheckOutLicenses(esriLicenseProductCode productCode)
{
esriLicenseStatus licenseStatus;

//是否产品是可能的
licenseStatus = m_AoInitialize.IsProductCodeAvailable(productCode);
if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
{

//用相应的许可文件进行初始化
licenseStatus = m_AoInitialize.Initialize(productCode);
}
return licenseStatus;
}

private string LicenseMessage(esriLicenseStatus licenseStatus)
{
string message = "";

//没有许可
if (licenseStatus == esriLicenseStatus.esriLicenseNotInitialized)
{
message = "You are not licensed to run this product!";
}
//许可正在使用
else if (licenseStatus == esriLicenseStatus.esriLicenseUnavailable)
{
message = "There are insuffient licenses to run!";
}
//未知错误
else if (licenseStatus == esriLicenseStatus.esriLicenseFailure)
{
message = "Unexpected license failure! Please contact your administrator.";
}
//已经初始化
else if (licenseStatus == esriLicenseStatus.esriLicenseAlreadyInitialized)
{
message = "The license has already been initialized! Please check your implementation.";
}
return message;
}
}
}  

===============================================================================

“http://hi.csdn.net/hulei_accp”

using ESRI.ArcGIS.esriSystem;

namespace WindowsApplication1
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  private void Form1_Load(object sender, EventArgs e)
  {
  IAoInitialize m_aoinitialize = new AoInitializeClass();
  m_aoinitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);  
  }
  }
}

我加上这个后,就没有出现这个“Warning: This application has not been initialized with an ESRI license and will not function correctly. ”提示了。

===============================================================================

arcengine 获得lic 信息

 private void button1_Click(object sender, EventArgs e)
        {

            ESRI.ArcGIS.esriSystem.IAoInitialize aoInitialize = new ESRI.ArcGIS.esriSystem.AoInitializeClass();
            ESRI.ArcGIS.esriSystem.ILicenseInformation licenseInformation = (ESRI.ArcGIS.esriSystem.ILicenseInformation)aoInitialize;

            System.String string_Licenses = null;
            try
            {

                ESRI.ArcGIS.esriSystem.esriLicenseProductCode licenseProductCode = aoInitialize.InitializedProduct();
                System.String string_LicenseProductName = licenseInformation.GetLicenseProductName(licenseProductCode);

                string_Licenses = "This application is initialized with the following product license:" + System.Environment.NewLine + string_LicenseProductName + System.Environment.NewLine + "This application has the following extension licenses checked out:";

                ESRI.ArcGIS.esriSystem.ILicenseInfoEnum licenseInfoEnum = licenseInformation.GetProductExtensions(licenseProductCode);

                licenseInfoEnum.Reset();

                ESRI.ArcGIS.esriSystem.esriLicenseExtensionCode licenseExtensionCode = licenseInfoEnum.Next();

                while (!(System.Convert.ToInt32(licenseExtensionCode) == -1))
                {

                    if (aoInitialize.IsExtensionCheckedOut(licenseExtensionCode) == true)
                    {
                        System.String string_LicenseExtensionName = licenseInformation.GetLicenseExtensionName(licenseExtensionCode);
                        string_Licenses = string_Licenses + System.Environment.NewLine + string_LicenseExtensionName;
                    }

                    licenseExtensionCode = licenseInfoEnum.Next();

                }
                System.Windows.Forms.MessageBox.Show(string_Licenses);

            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());

            }

        }

你可能感兴趣的:(看到的关于如何解决ArcEngine license 许可证的问题)