【问题标题】:Python Ctypes Load LibraryPython Ctypes 加载库
【发布时间】:2013-01-31 09:04:13
【问题描述】:

我使用的是 Windows 7 64 位机器。我安装了 Visual Studio 2010 并开发了一个简单的 win32 dll 来添加 2 个数字。创建了 dll,我使用测试应用程序测试了 dll,它工作正常。..

现在我编写 python 脚本(如下所示)来使用这个库。但我收到以下错误消息。

Traceback (most recent call last):
  File "C:\Users\sbritto\Documents\Visual Studio 2008\Projects\MathFuncsDll\Debug\MathFuncs.py", line 5, in <module>
    lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error=True)
  File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application

Python 脚本

import ctypes
from ctypes import *

#lib = cdll.LoadLibrary("MathFuncsDll.dll")
lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error=True)
print lib

请尽快告诉我。

提前致谢

【问题讨论】:

  • 您是否使用 64 位 Python 和 32 位 DLL,反之亦然?如果是这样,请不要:)

标签: visual-studio-2010 dll python-2.7 ctypes loadlibrary


【解决方案1】:

如果您尝试使用为 32 位机器编译的 Python 解释器打开 64 位 DLL,则会收到此错误,反之亦然。因此,如果这是一个 64 位 DLL,您需要确保您运行的是 64 位 Python。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2019-02-10
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多