//----------------------------------------MakeDll.h代码如下----------------------------------------#defineDLL_API__declspec(dllexport)#includeusingnamespacestd;...
// ---------------------------------------- MakeDll.h 代码如下 ----------------------------------------
#define DLL_API __declspec(dllexport)
#include
using namespace std;
DLL_API int add(int a, int b);
class DLL_API Point
{
private:
float x, y;
public:
Point();
};
// ---------------------------------------- MakeDll.cpp 代码如下 ----------------------------------------
#include "stdafx.h"
#include
using namespace std;
#include "MakeDll.h"
DLL_API int add(int a, int b)
{
return a + b;
cout << "a = " << a << "\tb = " << b << endl;
}
Point::Point()
{
x = 0.0f;
y = 0.0f;
cout << "x = " << x << "\ty = " << y << endl;
}
# --------------------------------------- python 调用 dll 如下 ------------------------------------
from ctypes import *
api = CDLL('MakeDLL')
a = c_int(1)
b = c_int(2)
x = c_float(0.1)
y = c_float(1.2)
c = api.add(a,b) # 报错:AttributeError: function 'add' not found
p = api.Point(x,y) #报错:AttributeError: function 'Point' not found
展开