【发布时间】:2018-05-05 13:31:59
【问题描述】:
我得到了一个由另一个人创建的 DLL,我无法访问它的原始 .cpp 和 .h 文件。基于描述 DLL 函数名称的描述文件,我将使用 Python 使用 ctypes 调用它们:
from ctypes import *
cppdll = WinDLL("C:\\VS_projects\\MusicServer_Flask\\NetServerInterface.dll")
py_InitNetwork = cppdll.InitNetwork
但是,我未能通过以下错误消息调用这些函数:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python35-32\lib\ctypes\__init__.py", line 360, in __getattr__
func = self.__getitem__(name)
File "C:\Python35-32\lib\ctypes\__init__.py", line 365, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'InitNetwork' not found
我认为函数名称可能存在一些问题。所以我使用 Dependency Walker 来检查 dll 函数的名称。不出所料,函数的名字很奇怪(InitNetwork 变成了?InitNetwork@@YAHQAD0H@Z):
我在网上搜索了一下,发现在制作这个DLL的时候,在编译的过程中出了点问题。
这是我的问题:让提供程序重新编译 DLL 是解决此问题的唯一方法吗?或者还有其他方法可以让我在 Python 中调用这些函数吗?
【问题讨论】:
-
我认为这里真正的问题不是名称混淆,而是缺少 C 接口。