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

xiaoxiao2021-02-28  84

自己摸索的  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

转载请注明原文地址: https://www.6miu.com/read-81160.html

最新回复(0)