C#调用C++文件

本文介绍了如何在C#中调用C++编写的dll文件,包括非托管和托管两种方式,并详细阐述了非托管方式下C++函数定义及C#的函数声明和使用。此外,还探讨了C#调用C++ .exe文件的方法,包括设置命令参数以及在C#中接收并显示C++进程输出数据的过程。
摘要由CSDN通过智能技术生成

一、C#调用C++ dll文件

1)非托管方式:

C++函数定义:

extern "C" __declspec(dllexport)void MyChangeDetection(const char * filepath1,const char *filepath2,int DImethod,int DIAnalysis,const char *outpath)
{
    ......
}

C#中,函数声明部分:

        [DllImport("CDdll.dll",CharSet=CharSet.Ansi,CallingConvention=CallingConvention.Cdecl)]  //,CharSet=CharSet.Ansi

        public static extern void MyChangeDetection(IntPtr filepath1, IntPtr filepath2, int DImethod, int DIAnalysis, IntPtr outpath);

函数使用部分:

MyChangeDetection(Intptr1, Intptr2, Dimethod1, DiAnalysismethod2, Intptr3);

注意C++与C#中类型转换:

public string pathname1, pathname2;
public string Dimethod, DiAnalysismethod;

public string outPath = Directory.GetCurrentDirectory()+"\\"+"CDmap.png";
private void button1_Click(object sender, EventArgs e)
       {
           OpenFileDialog file = new OpenF
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值