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

来源:互联网 发布:淘宝怎么修改店铺类目 编辑:程序博客网 时间:2024/05/21 14:01
自己摸索的  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

原创粉丝点击