Reputation: 3792
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.
Upvotes: 0
Views: 626
Reputation: 6066
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).
Upvotes: 2