ctypes加载dll时没有错误消息,但是什么也没有发生

2024-09-30 20:22:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用windll.LoadLibrary在ctypes中,将dll文件导入python。虽然没有任何错误消息,但头文件中列出的函数似乎都没有成功加载。我想知道dll文件是否有问题,或者我使用了windll.LoadLibrary方法不正确。在

可以从以下链接下载dll和头文件: http://www.cc.ncu.edu.tw/~auda/ATC3DG.rar

我使用的python命令是:

from ctypes import * 
libc=windll.LoadLibrary('ATC3DG.DLL')

可以从下面的链接查看结果,该链接显示dir(libc)没有给出ATC3DG.h中列出的任何函数或变量:

http://www.cc.ncu.edu.tw/~auda/ATC3DG.jpg

我在Windows7(64位)平台上使用Python2.7.3(32位)和iPython0.13.1。在

谢谢

张艾瑞克


Tags: 文件函数http头文件链接wwwctypescc
1条回答
网友
1楼 · 发布于 2024-09-30 20:22:20

当您使用dir时,它们不会出现,除非您已经访问过该函数。例如:

In [98]: from ctypes import cdll

In [99]: libc = cdll.LoadLibrary('libc.so.6')

In [100]: dir(libc)
Out[100]:
['_FuncPtr',
 '__class__',
 '__delattr__',
 '__dict__',
 '__doc__',
 '__format__',
 '__getattr__',
 '__getattribute__',
 '__getitem__',
 '__hash__',
 '__init__',
 '__module__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_func_flags_',
 '_func_restype_',
 '_handle',
 '_name']

In [101]: libc.printf
Out[101]: <_FuncPtr object at 0x65a12c0>

In [102]: dir(libc)
Out[102]:
['_FuncPtr',
 '__class__',
 '__delattr__',
 '__dict__',
 '__doc__',
 '__format__',
 '__getattr__',
 '__getattribute__',
 '__getitem__',
 '__hash__',
 '__init__',
 '__module__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_func_flags_',
 '_func_restype_',
 '_handle',
 '_name',
 'printf']

您可以通过查看CDLL.__getitem__CDLL.__getattr__方法来了解发生这种情况的原因:

^{pr2}$

相关问题 更多 >