Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

could not load c++ DLL in python

Tags:

c++

python

dll

I am trying to use a C++ .dll in Python, but I can't even load it. I am trying the following python code to load it:

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

But when I try to run this I get:

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

The last sentence means "%1 is not a valid Win32 application" in English.

I already looked it up at http://docs.python.org/2/library/ctypes.html#module-ctypes , but this didn't lead to a solution for my problem.

like image 732
nimp0u Avatar asked Nov 07 '12 07:11

nimp0u


Video Answer


1 Answers

Sounds like you have an incompatible version of Python installed or the DLL was compiled using the wrong settings. The DLL and the Python interpreter both have to be either 32 or 64 Bit.

like image 150
Pait Avatar answered Oct 12 '22 22:10

Pait