混合编程之二:c#调用c++pcl库,生成c#库类文件

本文档展示了如何在C# .NET类库中使用DllImport调用来导入C++编写的PCL库,包括加载PCD文件、获取点云大小、可视化点云以及应用过滤器等操作。通过这种方式,可以在Winform应用程序中无缝集成PCL库的功能。
摘要由CSDN通过智能技术生成

一、右击解决方案,添加,新建项目,生成.net类库文件

 在Class1.cs中写入如下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace sharpvtkdll
{
    public class Class1
    {
        //class pcdFile
        //{   //dll路径
            [DllImport("PCLdll.dll", EntryPoint = "loadPCDFile", CharSet = CharSet.Auto)]
            public static extern int loadPCDFile([MarshalAs(UnmanagedType.LPStr)] string str, double[] arr_X, double[] arr_Y, double[] arr_Z);

            [DllImport("PCLdll.dll", EntryPoint = "Size", CharSet = CharSet.Auto)]
            public static extern int Size([MarshalAs(UnmanagedType.LPStr)] string msg);

            [DllImport("PCLdll.dll", EntryPoint = "Cloud_Visual", CharSet = CharSet.Auto)]
            public static extern int Cloud_Visual([MarshalAs(UnmanagedType.LPStr)] string msg);

            [DllImport("PCLdll.dll", EntryPoint = "PassThoughPCDFile", CharSet = CharSet.Auto)]
            public static extern int PassThoughPCDFile([MarshalAs(UnmanagedType.LPStr)] string str, float[] arr_X, float[] arr_Y, float[] arr_Z);

            [DllImport("PCLdll.dll", EntryPoint = "ECFC", CharSet = CharSet.Auto)]
            public static extern int ECFC([MarshalAs(UnmanagedType.LPStr)] float a, float b, float c);

            public bool LoadFile(string strFile, ref double[] arr_X, ref double[] arr_Y, ref double[] arr_Z)
            {

                loadPCDFile(strFile, arr_X, arr_Y, arr_Z);
                return true;
            }

            public int PcdSize(string strFile)
            {
                int size = Size(strFile);
                return size;
            }


            public bool Cloud_visual(string strFile)
            {
                Cloud_Visual(strFile);
                return true;
            }

            public bool PassThoughPCD(string strFile, ref float[] arr_X, ref float[] arr_Y, ref float[] arr_Z)
            {

                PassThoughPCDFile(strFile, arr_X, arr_Y, arr_Z);
                return true;
            }

    }
}

二、 右击项目,点击生成,即在文件夹下生成相应的dll文件

(73条消息) 混合编程之三:c#调用c++pcl库,在winform项目中使用_chaonian16的博客-CSDN博客

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值