0

I have zero experience with c++ but reasonable experience with python. I am trying to load a dll library and proceeded as follows, according to instructions in another thread:

import ctypes my_dll = ctypes.WinDLL ("c:\\whatever\\whatever.dll") 

the response I get is:

Traceback (most recent call last): File "C:\Users\xxx\Anaconda3\lib\site- packages\IPython\core\interactiveshell.py", line 3035, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-6-8b21ed13fe33>", line 1, in <module> mydll = cdll.LoadLibrary(dll_path) File "C:\Users\xxxx\Anaconda3\lib\ctypes\__init__.py", line 429, in LoadLibrary return self._dlltype(name) File "C:\Users\xxx\Anaconda3\lib\ctypes\__init__.py", line 351, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 193] %1 is not a valid Win32 application 

The OS is 64-bit Windows 10. Could anyone point me to what is wrong?

Thanks.

1
  • 1
    Is the DLL also 64-bit? If it is, are you sure you're using the 64-bit version of Python? The DLL and the Python interpreter both have to be either 32 or 64 bit. Commented Dec 5, 2015 at 20:19

1 Answer 1

2

If the dll exists and is found, it might be that there is mismatch between 32-bit and 64-bit. For C++ app, the executable and the loaded dll must be the same architecture (either both 32-bit or both 64-bit), and the same applies for the Python executable. That means if you run 64-bit Python it might not be able to load a 32-bit dll and vice versa (there is actually a way to do it by creating helper 32-bit process and using IPC, but I'm not sure if Python does that).

I.e. check if both the dll and executable (Python) are the same architecture (bit size).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot E! yes, that was the issue - there was indeed a mismatch between 32 and 64 bits.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.