Take the 2-minute tour ×

I am trying to use a c++ dll in python but I cant 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:


Traceback (most recent call last):

File "D:...\src\SORT_DLL\Debug\UseDll.py", line 2, in

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 didnt lead to a solution for my problem.

share|improve this question
First, is it actually a cdll rather than a windll? Second, as the documentation says, you're not supposed to add the .dll suffix on Windows. –  abarnert Nov 7 '12 at 7:47
Also, one good way to debug ctypes problems loading libraries is to break the steps up explicitly. First try to use the native Win32 LoadLibrary (if you've got PyWin32, that's the easiest way; if not, you can ctypes the system DLL, I think it's user32, or you can use the undocumented wrapper in _ctypes.LoadLibrary) and see if you can get a handle. Then you can try to create a CDLL instance by calling the constructor with the explicit handle and see what happens. If the first step works but the second fails, try some explicit GetProcAddress calls with the handle. –  abarnert Nov 7 '12 at 7:55
add comment

3 Answers

up vote 4 down vote accepted

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.

share|improve this answer
Thanks. Although i have compiled the DLL for 64bit and had the Python 64bit version installed, it didn't work. Now i have the 32bit version of Python installed and everything works great. –  nimp0u Nov 7 '12 at 15:06
add comment

Refer to this answer: http://stackoverflow.com/a/10163943/953887

"ctypes doesn't work with C++, which the [DLL] example is written in."

share|improve this answer
add comment

this link is a complete example to creating and using .dll files via ctypes: Python | accessing dll using ctypes

share|improve this answer
add comment

Your Answer


