自己做的网站外网访问,有那些app开发公司,网网站基础建设优化知识,域名在哪里买Python调用c生成的dll 1.简单例子1.1 vs2019 c生成dll1.2 Python端调用 2.调用c类生成的dll2.1 vs cpp端生成dll2.2 Python端调用 参考文献 1.简单例子
1.1 vs2019 c生成dll
项目中添加add.cpp文件
extern C int __declspec(dllexport) add(int x, int y)
{retu… Python调用c生成的dll 1.简单例子1.1 vs2019 c生成dll1.2 Python端调用 2.调用c类生成的dll2.1 vs cpp端生成dll2.2 Python端调用 参考文献 1.简单例子
1.1 vs2019 c生成dll
项目中添加add.cpp文件
extern C int __declspec(dllexport) add(int x, int y)
{return x y;
}配置属性 生成dll 点击生成解决方案到输出目录文件夹查看add.dll文件是否正常生成。
1.2 Python端调用
from ctypes import*import sys
try:mydll cdll.LoadLibrary(radd.dll)
except:sys.exit(No shared DLL/SO found)print(mydll.add(3,4))
#72.调用c类生成的dll
2.1 vs cpp端生成dll
添加myDll.cpp文件
#includeiostream
using namespace std;
class myDll
{
public:void helloDll() {cout hello dll endl;};
};extern C
{myDll obj;extern C _declspec(dllexport) void helloDll() {return obj.helloDll();}
}
配置属性
dll名设置为myDll.
生成dll文件
参考第一个例子。
2.2 Python端调用
from ctypes import*import sys
try:mydll cdll.LoadLibrary(myDll.dll)
except:sys.exit(No shared DLL/SO found)mydll.helloDll()#hello dll测试通过
参考文献
[1] python调用dll 结构体 python如何调用dll 转载