python代码:
import ctypes as C
dll = C.cdll.LoadLibrary('Dll1.dll')
#1.传入实数调用demo
result1 = dll.add(2,3)
print(result1)
C++:
Dll1.cpp:
#include "pch.h"
#define DLLEXPORT extern "C" _declspec(dllexport)
DLLEXPORT int add(int a, int b)
{
return a + b;
}
Dll1.h:
#define DLL1_API _declspec(dllexport)
class DLL1_API CDll1
{
public:
CDll1(void);
int add(int a, int b);
};
extern DLL1_API int nDll1;
DLL1_API int fnDll1(void);
调用结果: