1. 创建.dll文件

首先建立动态链接库项目
用VS2017 15.9.3版本编写C++动态链接库 和 python调用dll
在VS创建的.cpp文件中编写你的C++代码
并在开头加上以下代码

extern "C" _declspec(dllexport) return_type func_name(type1 parameter1 [, type2 parameter2 [, ...]]);

生成解决方案 (Ctrl + Shift + B)
然后就可以在项目文件夹中找到已经生成的 .dll 文件了。

注意:根据你的python是32位还是64位选择生成32位还是64位的.dll文件

2. python调用C++动态链接库

调用 .dll 文件一般使用 ctypes 库

from ctypes import *

dll = cdll.LoadLibrary ("Absolute Path")

'''调用C++函数'''
dll.func_name(argument1 [,argument2 [...]])

相关文章:

  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2021-11-21
  • 2022-01-15
  • 2021-07-29
猜你喜欢
  • 2021-11-05
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案