Python Ctypes加载库 [英] Python Ctypes Load Library
问题描述
现在我编写python脚本(如下所示)来使用这个库。但是我收到以下错误消息。
追溯(最近的最后一次呼叫):
文件C:\ Users &\\sbritto\Documents\Visual Studio 2008\Projects\MathFuncsDll\Debug\MathFuncs.py,第5行,< module>
lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error = True)
文件C:\Python27\lib\ctypes\__init __。py,第365行,__init__
self._handle = _dlopen(self._name,mode)
WindowsError:[错误193]%1不是有效的Win32应用程序
Python脚本
import ctypes
从ctypes import *
#lib = cdll.LoadLibrary(MathFuncsDll.dll)
lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error = True)
打印lib
请尽快让我知道。
提前感谢
如果您尝试使用Python解释器打开64位DLL,您将收到此错误为32位机器编译,反之亦然。所以,如果这是一个64位的DLL,你需要确保你运行一个64位的Python。
I am using windows 7 64 bit machine. I installed Visual studio 2010 and developed a simple win32 dll to add 2 numbers.. The dll is created and i used a test application to test the dll and it works fine..
Now i write python script(shown below) to use this library. But i get the following error message.
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 Script
import ctypes
from ctypes import *
#lib = cdll.LoadLibrary("MathFuncsDll.dll")
lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error=True)
print lib
Kindly let me know ASAP.
Thanks in advance
You'll get this error if you try to open a 64-bit DLL using a Python interpreter compiled for a 32-bit machine, or vice versa. So, if this is a 64-bit DLL you need to make sure you are running a 64-bit Python.
这篇关于Python Ctypes加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!