C++CLI调用ArcObjects
更新时间:2023-09-16 08:18:01 阅读量: 高中教育 文档下载
- cclink通讯协议推荐度:
- 相关推荐
1新建一个空的工程命名为AoWrapperDemo
2 添加一个新项目,命名为AoWrapper
右键项目-》属性,添加ESRI.ArcGIS相关引用
将配置类型改为动态链接库
添加一个c++文件,命名为GeometryWrapper
由于该类功能简单,没必要添加头文件
using namespace System;
using namespace System::Diagnostics; using namespace ESRI::ArcGIS::Geometry; using namespace ESRI::ArcGIS::esriSystem; using namespace ESRI::ArcGIS; namespace AoWrapper {
}
~GeometryWrapper() { }
public ref class GeometryWrapper { public:
pAoInitialize->Initialize(esriLicenseProductCode::esriLicenseProductC
GeometryWrapper() {
ESRI::ArcGIS::RuntimeManager::Bind(ProductCode::Engine); IAoInitialize^ pAoInitialize=gcnew AoInitializeClass();
odeEngineGeoDB);
}
public: };
int line_test() { }
IPoint ^ ipPt1 =gcnew PointClass(); IPoint ^ ipPt2 =gcnew PointClass(); ipPt1->PutCoords(1, 2); ipPt2->PutCoords(2, 3);
ILine^ ipLine=gcnew LineClass(); Stopwatch^ watch=gcnew Stopwatch(); watch->Start();
for(long i=0;i<=10000000; i++) { }
watch->Stop();
Console::WriteLine(watch->ElapsedMilliseconds); return 0;
ipLine->PutCoords(ipPt1,ipPt2); //Console::WriteLine(i);
完成C++/CLI对ArcObjects的调用封装类库
3 添加一个新项目,命名为NAoHelper,利用本地c++直接操作AO
修改头文件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
#pragma once
#include \ using namespace System; namespace NAoWrapper { }
public ref class RefAoWrapper { };
// TODO: Add your methods for this class here. AoHelper *ao; int line_test(); RefAoWrapper(); ~RefAoWrapper(); private: public:
修改NAoWrapper.cpp
// This is the main DLL file.
#include \ #include \
using namespace System::Diagnostics;
namespace NAoWrapper {
int RefAoWrapper ::line_test() {
Stopwatch^ watch=gcnew Stopwatch(); watch->Start();
RefAoWrapper::~RefAoWrapper() { }
delete ao;
RefAoWrapper::RefAoWrapper() { }
ao=new AoHelper();
}
}
ao->line_test(); watch->Stop();
Console::WriteLine(watch->ElapsedMilliseconds); return 0;
5 添加新项目,命名为CSharpAoHeleper,C#直接调用ArcObjects
添加ESRI.ArcGIS.相关引用
将Class1.cs重命名为CSharpAoHeleper,代码如下
using System;
using System.Collections.Generic; using System.Linq; using System.Text;
using ESRI.ArcGIS.Geometry; using System.Diagnostics;
namespace CSharpAoHeleper {
public class CSharpAoHeleper {
public int line_test() {
IPoint ipPt1 = new PointClass(); IPoint ipPt2 = new PointClass(); ipPt1.PutCoords(1, 2); ipPt2.PutCoords(2, 3);
ILine ipLine = new LineClass();
Stopwatch watch = new Stopwatch(); watch.Start();
for (long i = 0; i <= 10000000; i++) {
ipLine.PutCoords(ipPt1, ipPt2); //Console::WriteLine(i); }
watch.Stop();
Console.WriteLine(watch.ElapsedMilliseconds);
return 0; } } }
编译,完成C#直接操作AO封装库
6 添加新项目,命名为Test
右键项目属性,修改输出路径(Output path):即AoWrapperDemo\\Debug目录
添加ESRI.AcrGIS.相关引用 添加项目引用
修改Program.cs
using System; using ESRI.ArcGIS;
using ESRI.ArcGIS.esriSystem;
namespace Test {
static class Program {
///
/// The main entry point for the application. /// [STAThread]
static void Main() {
if (!RuntimeManager.Bind(ProductCode.Engine))
正在阅读:
C++CLI调用ArcObjects09-16
《孔乙己》(5篇)08-22
高中政治一年级07-12
操作系统2014课程设计01-28
vsp5.0最新试题答案11-06
2016年东财《组织行为学》在线作业答案06-30
2011年全国大学生英语竞赛B类初赛赛卷及听力材料与答案03-08
采矿学试题 - 图文10-09
五代十国方镇年表(二)04-07
- 上海大众、一汽大众、东风日产车型与VIN代号对照表
- 第2章服装原型及原型制作
- 江苏省工商行政管理系统经济户口管理办法及四项制度
- 纪检监察业务知识试题2
- 传感器综合题答案
- 北京第二外国语学院翻硕招生人数及学费
- 初三新编英语教材下册
- 公司庆中秋、迎国庆联欢会客串词
- 向区委常委会汇报安全生产工作材料
- 2006年GCT英语模拟试题(三)及答案解析
- 经济法概念的早期使用
- 我爱做家务课堂教学设计
- 学校安全工作月报表、消防安全排查表、消防隐患排查台账
- 成本会计毕业论文
- 班级文化建设论文
- 2018年天津市高考文科试题与答案汇总(Word版) - 图文
- 铁路论文
- 2017年嵌入式系统设计师考试时间及地点
- 1.111--灾害与突发公共卫生事件应急预案
- 起爆点主图 注意买入 拉升 逃顶源码指标通达信指标公式源码
- 调用
- ArcObjects
- CLI
- 智慧城市群发展路径分析
- 重庆市国土房管局-渝国土房管发92号
- 石家庄铁道大学混凝土结构设计期末2010土木期末
- 品味母爱群文阅读教学设计
- 中国土特产行业市场前景分析预测报告 - 图文
- 柳体书法基本笔法与结构
- 2015年最新人教版二年级下册数学全册教案
- 《化工原理I》计算试题考研真题1(6)
- 计算机概论九讲复习的答案
- 可逆电池的电动势及其应用-学生
- 2014年咖啡杯行业市场调研报告
- 信号与系统期末考试复习资料
- 《静夜思》说课稿
- 从传播学角度探讨外宣翻译 - 以上海世博会材料英译得失为例
- 2016年一建培训资料案列重点课件
- 2015高考化学有机信息方程式(结构简式)的书写(1)
- 《争当孝心少年》主题班会
- 法律事务管理工作总结
- 牧原股份猪舍监控系统原理结构与安装调试 周耀昌 1402314040 测控技术与仪器 - 图文
- 2017年上半年陕西省基金从业资格:远期、期货合约等区别考试试题