4

We are trying to connect to an external piece of hardware using a DLL and faced a problem we were not able to solve so far. Our platform is Windows 7, 64 bit, and we are using Python 2.7, also 64 bit, to write a driver. The DLL we are using is also 64 bit (we double checked that with the PE Deconstructor). We use ctypes to load the DLL, specifically:

import ctypes

ctypes.cdll.LoadLibrary('dllpath')

...

However, we get the error message [Error 193] %1 is not a valid Win32 application. The same happens if we try to load 32 bit DLLs or use the commands pydll, oledll or windll. Do you have an idea how we could load the DLL or what the solution might be?

We would be very grateful for a helpful answer,

Best, Florian

Community
  • 1
  • 1
  • Is your python.exe visible in system variables path? – Aleksandar Dec 09 '14 at 14:25
  • Sounds like a bitness mismatch. Either in the DLL or its dependencies. Check using Dependency Viewer, for instance. – David Heffernan Dec 09 '14 at 14:28
  • 1
    `cdll` and `windll` are loaders that wrap `CDLL` and `WinDLL`, to cache loaded libraries and make it easy to access Windows DLLs when the base filename is a syntactically valid identifier, e.g. `cdll.msvcr100`. The `LoadLibrary` method just calls the wrapped class and doesn't cache the library, so you may as well use `ctypes.CDLL('dllpath')`. – Eryk Sun Dec 09 '14 at 16:10
  • 1
    As to loading the DLL, there's no difference between `CDLL` and `WinDLL`. The latter just sets a flag on function pointers to use `stdcall` instead of `cdecl`. In 64-bit Windows there's no difference anyway since there's only one standard calling convention for exported functions. – Eryk Sun Dec 09 '14 at 16:12
  • Are all the dependencies present? If the DLL requires other DLLs to operate that may be the cause. – Mark Tolonen Dec 11 '14 at 02:14

1 Answers1

0

You are mixing 32 bit and 64 bit. I did the same, Win 7 64 bit, Python 64 bit, but a third party hardware dll 32 bit. Answer, remove Python 64 bit, install Python 32 bit. A good discussion here: https://bytes.com/topic/python/answers/789333-ctypes-64-bit-windows-32-bit-dll

wdanford
  • 1
  • 3