无法在Python中加载C DLL

could not load c++ DLL in python

本文关键字:加载 DLL Python      更新时间:2023-10-16

我试图在Python中使用C .dll,但我什至无法加载它。我正在尝试以下Python代码加载:

from ctypes import cdll
mydll = cdll.LoadLibrary('SORT_DLL.dll')

但是当我尝试运行这个时,我会得到:

D:...srcSORT_DLLDebug>UseDll.py
Traceback (most recent call last):
  File "D:...srcSORT_DLLDebugUseDll.py", line 2, in
 <module>
    mydll = cdll.LoadLibrary('SORT_DLL.dll')
  File "C:Python27libctypes__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "C:Python27libctypes__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 ist keine zulõssige Win32-Anwendung

最后一句话是指英文中的"%1不是有效的win32应用程序"。

我已经在http://docs.python.org/2/library/ctypes.html#module-ctype上查找了它,但这并没有导致解决我的问题的解决方案。

听起来您已经安装了Python的不兼容版本,或使用错误的设置编译了DLL。DLL和Python解释器都必须为32或64位。

请参阅此答案:https://stackoverflow.com/a/10163943/953887

" ctypes不适用于c ,[dll]示例写在其中。"