我是C++的完全入门者,一直在尝试通过ctypes使用DLL从Python访问C++函数。
运行代码时,我总是收到错误AttributeError: function 'my_function' not found
。
header
#pragma once
int my_function(void);
Source.cpp
#include "Header.h"
int my_function(void)
{
return(17); //test
}
ctypesTest.py
import ctypes
if __name__ == "__main__":
mydll = ctypes.CDLL("MyDLL.dll")
print(mydll.my_function())
每次我运行Python脚本时,都会出现属性错误。
我只需要预期功能中的值。
最佳答案
@Mikel Rychliski回答了我的问题。
header
#pragma once
#define DllExport __declspec( dllexport )
extern "C"
{
__declspec(dllexport) int my_function(void);
}
关于python - ctypes找不到find dll函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61263597/