修改头文件stdafx.h,导入ArcObjects相关库
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently //
#pragma once
#include \
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files: #include
// TODO: reference additional headers your program requires here #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 \ raw_interfaces_only, raw_native_types, no_namespace, named_guids, exclude(\, \, \)
#import \ raw_interfaces_only, raw_native_types, no_namespace, named_guids,exclude(\) // Load the ArcGISVersion library.
// This code is commonly placed in the StdAfx.h header file. #import \ raw_interfaces_only,no_implementation
添加一个头文件NAoHelper.h
修改后的头文件如下:
#ifndef AOHELPER_H_ #define AOHELPER_H_ #ifdef NAOHELPER_EXPORTS
#define DAPI __declspec(dllexport) #else
#define DAPI __declspec(dllimport) #endif
//导出这个类
class DAPI AoHelper { public: }; #endif
AoHelper(); ~AoHelper(); int line_test(); int InitializeAo();
private:
打开NAoHelper.cpp,修改后如下:
// NAoHelper.cpp : Defines the exported functions for the DLL application. //
#include \ #include \
AoHelper::AoHelper() { }
AoHelper::~AoHelper() { }
int AoHelper::InitializeAo() {
esriLicenseStatus ls; HRESULT h=
IAoInitializePtr m_AoInit;//(CLSID_AoInitialize); m_AoInit.CreateInstance (CLSID_AoInitialize); ArcGISVersionLib::IArcGISVersionPtr VARIANT_BOOL succeeded;
if (FAILED(ipVer->LoadVersion(ArcGISVersionLib::esriArcGISDesktop ,
return 0;
ipVer(__uuidof(ArcGISVersionLib::VersionManager));
::CoUninitialize(); ::CoInitialize(NULL); //不初始化也可以 //InitializeAo();
L\,&succeeded)))
m_AoInit->Initialize(esriLicenseProductCode::esriLicenseProductCodeEngineGeoDB ,&ls); }
int AoHelper::line_test() {
IPointPtr ipPt1(CLSID_Point); IPointPtr ipPt2(CLSID_Point); ipPt1->PutCoords(1, 2); ipPt2->PutCoords(2, 3); return 0;
}
ILinePtr ipLine(CLSID_Line);
for(long i = 0; i <= 10000000; i++) { }
return 0;
ipLine->PutCoords(ipPt1,ipPt2);
编译,完成本地c++调用AO封装类库
4 添加新项目,命名为NAoWrapper,利用C++/CLI对NAoHelper进行封装的库,以便于C#调用
编辑包含文件(头文件)目录
修改头文件NAoHelper.h
// NAoWrapper.h
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新高中教育C++CLI调用ArcObjects (2)全文阅读和word下载服务。
相关推荐: