【问题标题】:Python and C-dll with invalid name of function函数名称无效的 Python 和 C-dll
【发布时间】:2012-08-10 00:00:06
【问题描述】:

我在 python 中使用 DLL 函数时遇到问题。 我通过“dumpbin”查看了函数的名称。

例如

_xGraphics3D@20

我尝试这样调用函数:

from ctypes import *
xorsLib =  cdll.LoadLibrary("Xors3D.dll")
width = c_int(800)
height = c_int(600)
depth = c_int(32)
mode = c_int(0)
vsync = c_int(0)
xGraphics3D = getattr(xorsLib,"_xGraphics3D@20")
xGraphics3D(width, height, depth, mode, vsync)

但它会导致错误:

Traceback (most recent call last):
  File "D:/Coding/Python/pyASG/main", line 11, in <module>
    xGraphics3D(width, height, depth, mode, vsync)
ValueError: Procedure called with not enough arguments (20 bytes missing) or wrong calling convention

我做错了什么?

附言我不知道python,但我学会了。我阅读了 ctype-manual 并试图找到答案...

p.p.s 对不起我糟糕的英语。

【问题讨论】:

  • 在我的脑海中,您是否有机会使用 C++ 编译器?如果是这样,您可能需要声明您的函数 extern "C" 以防止 C++ 的正常名称修改。参见例如this 文章。
  • 这不是我的图书馆,我无权访问源代码。

标签: python windows


【解决方案1】:

尝试使用windll而不是cdll。
xorsLib = windll.LoadLibrary("xors3d.dll") http://docs.python.org/release/3.1.5/library/ctypes.html
原因和martineau评论的一样。

【讨论】:

  • @user1588891:习惯上也会对您接受的答案进行投票。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-19
  • 2018-12-14
相关资源
最近更新 更多