c/c++ developer
https://github.com/PengShiqiu

导航

 

1、在头文件中按照如下格式编写函数申明

extern "C" __declspec(dllexport) double __stdcall Add(double a, double b);

 

2、在cpp文件中按照如下实现函数

double __stdcall Add(double a, double b)
{
return a + b;
}

 

 

3、创建一个def文件,用于描述导出后的函数名,防止生成不一致问题和其他语言调用问题

 

def文件中编写内容如下:

LIBRARY "Dll1"
EXPORTS
 Add @ 1

 

 

4、创建C#工程,在对应的类中增加如下代码直接调用C++动态库中的函数

[DllImport(@"F:\C++\DllTest\Dll1\Release\Dll1.dll")]
static extern double Add(double a, double b);

 

posted on 2019-07-03 00:20  Pengshiqiu  阅读(375)  评论(0编辑  收藏  举报