动态库dll编写经验

流程

(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);
posted @   lvye1221  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示