0
点赞
收藏
分享

微信扫一扫

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

开源分享 2022-03-11 阅读 58

一、右击解决方案,添加,新建项目,生成.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文件

举报

相关推荐

0 条评论