我是一个学c++的学生, 写了个dll给python调用,报错win1114
class.h
#ifndef __CLASS_H__
#define __CLASS_H__
class a
{
public:
int fac(int z);
void setx(int z);
private:
int x;
};
#endif
class.cpp
#include "class.h"
#include <windows.h>
#include <cstdio>
int a::fac(int z)
{
if(z == 1)
return 1;
return z*fac(z-1);
}
void a::setx(int z)
{
x = z;
}
interface.h
#ifndef _DLL_H_
#define _DLL_H_
#define DLLIMPORT __declspec(dllexport)
extern"C"
{
#include "class.h"
}
extern "C"
{
DLLIMPORT int fac(a* A,int z);
DLLIMPORT void setx(a* A,int z);
DLLIMPORT a* makea();
}
#endif
interface.cpp
#include"interface.h"
int fac(a* A,int z)
{
return A->fac(z);
}
void setx(a* A,int z)
{
A->setx(z);
}
a* makea()
{
return new a();
}
然后用python调用
test.py
from ctypes import *
c_lib = CDLL('E:/dlltest/Project3.dll')
报错
D:\python\python.exe C:/Users/mcc2018/PycharmProjects/untitled1/test.py
Traceback (most recent call last):
File "C:/Users/mcc2018/PycharmProjects/untitled1/test.py", line 2, in <module>
c_lib = CDLL('E:/dlltest/Project3.dll')
File "ctypes\__init__.py", line 369, in __init__
OSError: [WinError 1114] 动态链接库(DLL)初始化例程失败。
Process finished with exit code 1
请各位前辈大工程师们帮帮我