return a+b; }3. 编译工程。4. 建立新的C#工程,选择Console应用程序,建立测试程序InteropDemo5. 在Program.cs中添加引用:using System.Runtime.InteropServices;6. 在pulic class Program添加如下代码:using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
namespace InteropDemo { class Program { [DllImport("CppDemo.dll", EntryPoint = "Add", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] public static extern int Add(int a, int b); //DllImport请参照MSDN