Python Ctypes Load Library

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 04:02:33

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/14621932/python-ctypes-load-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!