柚子快报邀请码778899分享:动态库dll编写经验

http://www.51969.com/

流程

(1)新建 dll 工程,空白工程即可

(2)编写 接口 代码

(3)添加 def 文件,用这个最省事

def 文件说明:

LIBRARY geos-function

EXPORTS

isPointInPolygon_GF

C# 调用 c++ 编写的动态库

注意 入口函数 的大小写,用 WinDbg 工具查看

[DllImport("geos-function.dll", EntryPoint = "isPointInPolygon_GF", ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]

public static extern int isPointInPolygon_GF(int n, IntPtr pData);

调用关键代码,注意:参数字节大小,double是8个,同时注意 数组元素的长度:

IntPtr data = Marshal.AllocHGlobal(8 * arrDataLen);

Marshal.Copy(arrData, 0, data, arrDataLen);

var ret = isPointInPolygon_GF(n, data);

Marshal.FreeHGlobal(data);

柚子快报邀请码778899分享:动态库dll编写经验

http://www.51969.com/

查看原文