一、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