I'm using python 3.10 64 bits and I want to load a 64 bits dll library using ctypes.
import os.path
import ctypes
dll_name = "USBLib.dll"
dllabspath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dll_name
myDll = ctypes.CDLL(dllabspath)
However, with this code I get the following error: FileNotFoundError: Could not find module 'c:\Users\DELL\Documents\python\USBlib\USBLib.dll' (or one of its dependencies). Try using the full path with constructor syntax.
.
Even when I use os.add_dll_directory(os.path.dirname(os.path.abspath(__file__)))
, it does not change.
What is strange is that I also have the 32 bits version of the library and ctypes is able to find it. I just get the error [WinError 193] %1 is not a valid Win32 application
which is normal.
What is wrong in the way I am loading the library ?