# 导入 ctypes 库,用于调用 DLL
import ctypes
# 加载 DLL 文件
# 假设我们有一个名为 example.dll 的动态链接库
dll = ctypes.CDLL('./example.dll')
# 定义函数原型,假设 DLL 中有一个名为 add 的函数,接收两个整数并返回一个整数
# 我们使用 argtypes 和 restype 来指定参数类型和返回值类型
dll.add.argtypes = (ctypes.c_int, ctypes.c_int)
dll.add.restype = ctypes.c_int
# 调用 DLL 中的 add 函数
result = dll.add(3, 4)
# 打印结果
print(f"Result of adding 3 and 4 is: {result}")
ctypes 是 Python 内置的一个库,用于在 Python 程序中调用 C 共享库(即 DLL 文件)中的函数。ctypes.CDLL 方法加载 DLL 文件。这里假设 DLL 文件名为 example.dll,并且位于当前工作目录下。add 的函数,它接收两个整数并返回一个整数。dll.add(3, 4) 来执行 DLL 中的 add 函数,并将结果存储在 result 变量中。如果你的 DLL 文件有其他函数或不同的参数类型,请根据实际情况调整代码。
上一篇:python mkdir
下一篇:python随机函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站