【发布时间】:2021-03-21 21:51:55
【问题描述】:
我正在尝试使用带有 ctypes 模块的 Python 3.8 调用 DLL 中的函数。
DLL 中的函数名是__apiJob()。注意,这个函数以双下划线开头。
我想在自定义对象中调用它,例如:
class Job:
def __init__(self,dll_path):
self.windll = ctypes.WinDLL(dll_path)
def execute(self):
self.windll.__apiJob()
a = Job('api64.dll')
a.execute()
但是由于函数名以双下划线开头,在 Python 中以 mangling 函数命名,会被视为私有方法。因此,在运行此脚本时,__apiJob 将被重命名为 _Job_apiJob,从而导致错误:"_Job__apiJob" not found。
我该如何处理这种情况?
【问题讨论】:
标签: python dll ctypes private name-mangling