您的位置:首页 > 编程语言 > C语言/C++

C#调用C++dll方法,char*类型之间的传递

2016-09-15 11:53 771 查看
char*类型之间的传递是关键,下面贴出来具体实现方法:

c++ dll中的函数导出如下:

extern "C" LIB_BASE_PROCESS_API bool _stdcall ExtractImgArea(const char* strSrcFilePath, const char* strOutShpFilePath, bool bReprojectToBL, bool bRemoveInnerBkv=true, double dfSimplifyValue=1); 

c#调用方法如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.InteropServices;

namespace ConsoleApplication1

{

    class Program

    {

        [DllImport(@"ImgBaseProcess.dll", EntryPoint = "ExtractImgArea",

            CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

        extern unsafe static bool ExtractImgArea(StringBuilder src, StringBuilder shp, bool t, bool b, double d);

        static void Main(string[] args)

        {

            double s = 1.0;

            StringBuilder strSrc = new StringBuilder("D:\\src.img");

            StringBuilder strShp = new StringBuilder("D:\\src.shp");

            bool isok = ExtractImgArea(strSrc, strShp, true, true, s);

          

            Console.WriteLine(isok);

            Console.ReadKey();            

        }

        

    }

}

记录以便以后遇到类似问题,便于查询解决,也为广大爱好者提供参考。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# C#调用dll方法