osgEarth C++轉換爲ActiveX控件

本文主要介紹osgEarth C++程序如何轉換爲ActiveX控件。
1、創建win32dll應用程序,並添加osgEarth代碼。
在這裏插入圖片描述
2、配置包含路徑、庫路徑和鏈接庫:
在這裏插入圖片描述

D:\OSG_PATH\Osg3.4.0_SDK\lib;D:\OSG_PATH\OsgEarth2.8_SDK\lib;
D:\OSG_PATH\Osg3.4.0_SDK\include;D:\OSG_PATH\OsgEarth2.8_SDK\include;

在這裏插入圖片描述

osg.lib;osgUtil.lib;osgDB.lib;osgGA.lib;osgViewer.lib;osgEarth.lib;osgEarthUtil.lib;osgEarthFeatures.lib;osgEarthSymbology.lib;OpenThreads.lib;osgEarthAnnotation.lib;osgParticle.lib;osgText.lib;

3、按照以下步驟創建導入到DLL的方法:
示例:
導出osgRun方法
在 project_name.cpp文件中添加如下代碼:

extern "C"  __declspec(dllexport) int  osgRun(HWND hWnd, bool isfullscreen, int recwidth, int recheight);

int osgRun(HWND hWnd, bool isfullscreen, int recwidth, int recheight)
{
	mOSG = new osgCoreLib(hWnd);
	mOSG->InitOSG(isfullscreen, recwidth, recheight);
	return 1;
}

創建 osgCore.def文件,添加到模塊定義文件,並在文件中添加如下代碼:
在這裏插入圖片描述
在這裏插入圖片描述

LIBRARY osgCore.dll
EXPORTS  
osgRun  

4、將生成的dll、lib等文件複製到C#程序的生成路徑:
在這裏插入圖片描述
在這裏插入圖片描述
5、在需要調用的C#程序中通過如下方法進行調用:

 [DllImport(@"osgCore.dll", EntryPoint = "osgRun", CallingConvention = CallingConvention.Cdecl), SecuritySafeCritical]
private static extern int osgRun(IntPtr hWnd, bool isfullscreen, int recwidth, int recheight);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章