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

C#调用C++ 动态链接库DLL

2017-06-08 14:58 375 查看
自己摸索的  c#自己创建个类 申明调用方法 注意调用约定使用C默认调用约定
public class CDLLFuntion
{
[DllImport(@"C:\Users\Administrator\Desktop\C#forC\CDLL\Debug\CDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public extern static int Add(int conn, int val);
}

按钮事件调用

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(CDLLFuntion.Add(1, 2).ToString());
}


c++定义导出函数

extern "C" __declspec(dllexport)  int Add(int plus1, int plus2)
{
int add_result = plus1 + plus2;
return add_result;
}


源码:http://download.csdn.net/detail/srx942173347/9864655
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: