创建动态链接库:
ControlerMainDll.h
#ifdef CONTROLER_EXPORTS
#define CTRL_API __declspec(dllexport)
#else
#define CTRL_API __declspec(dllimport)
#endif
#include <iostream>
using namespace std;
extern "C"
{
CTRL_API int add(int a, int b);
CTRL_API int test();
}
ControlerMainDll.cpp
#include"ControlerMainDll.h"
CTRL_API int add(int a, int b)
{
return a + b;
}
CTRL_API int test()
{
return 3;
}
C#调用:
API.cs
using System.Runtime.InteropServices;
namespace Test
{
public static class API
{
[DllImport("CPlusControler.dll", CallingConvention = CallingConvention