我正在学习如何使用原生 Windows dll
文件与 Python3
与硬件
进行交互。但是使用 ctypes 我可以找到 dll
文件,但是无法找到 dll
中公开的功能。
我在 google
、stackoverflow
等各个地方进行了搜索,但无法找到问题的解决方案。
例如:
import ctypes
data = ctypes.CDLL("WWanAPI.dll")
当我尝试 dir(data)
功能时,我得到了以下响应:
['_FuncPtr'、'__class__'、'__delattr__'、'__dict__'、'__dir__'、'__doc__'、'__eq__'、'__format__'、'__ge__'、'__getattr__'、'__getattribute__'、'__getitem__ ', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__'、'__sizeof__'、'__str__'、'__subclasshook__'、'__weakref__'、'_func_flags_'、'_func_restype_'、'_handle'、'_name']
任何见解都将有助于找到 dll
的所有功能。
最佳答案
ctypes
模块不提供此类功能,因为 Windows 没有提供用于迭代 DLL 内容的函数。
您想要的是检查 DLL 的内容。它只是一个文件,并且位于“可移植可执行文件”( PE format ) 中,因此您需要可以读取该格式文件的机制。
如果您只需要一个命令行工具,请查看 dumpbin。
一个很好的答案:https://stackoverflow.com/a/24732280/963195 以及这里的各种好的答案:Is there a way to find all the functions exposed by a dll
...这是一个 Python 模块:
关于python-3.x - 如何使用Python3从dll中查找函数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58839481/