可可西

AE安装检测(C++)

在MFC中使用AE(AO)进行二次开发时,当目标机器上若没有安装AE的Runtime,程序会直接挂掉。

对此,通过在CXXAppInitInstance()起始处增加环境的检测代码,来友好地提示用户安装AE的Runtime。

代码如下:

 1 BOOL CMap2DApp::InitInstance()
 2 {
 3     CoInitialize(NULL);
 4 
 5     try
 6     {
 7         IAoInitializePtr ipAoInitialize(CLSID_AoInitialize);
 8         if (ipAoInitialize==NULL)
 9         {
10             MessageBox(NULL,"请先安装ArcGIS Engine Runtime!","Map 2D",MB_OK|MB_ICONEXCLAMATION);
11             CoUninitialize();
12             return FALSE;
13         }
14         esriLicenseStatus licenseStatus;
15         HRESULT hr = ipAoInitialize->Initialize(esriLicenseProductCodeEngine,&licenseStatus);
16         
17         if (licenseStatus!=esriLicenseCheckedOut)
18         {
19             MessageBox(NULL,"请先安装ArcGIS Engine Runtime!","Map 2D",MB_OK|MB_ICONEXCLAMATION);
20             CoUninitialize();
21             return FALSE;
22         }
23     }
24     catch (...)
25     {
26         MessageBox(NULL,"请先安装ArcGIS Engine Runtime!","Map 2D",MB_OK|MB_ICONEXCLAMATION);
27         CoUninitialize();
28         return FALSE;
29     }
30 }

 

posted on 2012-04-30 16:07  可可西  阅读(952)  评论(0编辑  收藏  举报

导航