Spent 2 days with the same problem on Win10 PC Using Python 3.10.2 x64.
Simple python code:
import os
import sys
import ctypes
aqui = os.getcwd()
print(aqui)
os.add_dll_directory(aqui)
if os.path.exists('LibFT260.dll'):
print('Found LibFT260.dll.')
else:
print('Failed to find LibFT260.dll.')
quit()
ft = ctypes.windll.LoadLibrary('LibFT260.dll')
print(ft.FT260_GetChipVersion)
Error line:
> ft = ctypes.windll.LoadLibrary('LibFT260.dll') with or w/o '.dll' suffix.
I put `LibFT260.dll` in the working directory (where I call the Python script) and the code adds that path to the os.add_dll_directory. These were the 2
major fixes mentioned on the internet; neither worked.
[FYI: The only ctypes library load statement that would work was
ft = ctypes.WinDLL('LibFT260.dll', winmode = 1)
Microsoft LoadLibraryEx docs say not to use winmode = 1, it is only for backwards compatibility, so I changed to winmode = 48 which was suggested as one alternative.
(I never tried None, but 0 always failed, all other non-zero worked.)]
I ran the exact same program above on a 2nd PC and the LoadLibrary() function worked!
Details and the solution:
Machine 2 LoadLibrary() works
Lenovo P53s x64
Win10 21H2 build 19044.1526
Python 3.9.0 (x64)
Machine 1 LoadLibrary() doesn't work
Lenovo W530 x64
Win10 20H2 build 19042.1586
Python 3.10.2 (x64)
tried Python 3.9.0 (x64) still didn't work.
Then I noticed many Visual C++ differences between the machines.
The P53s had a more Visual C++ versions installed.
When I matched those versions on the W530 the code above worked on Machine 1.
I don't know which versions I had and which I added new, but this list worked:
(I have both the x64 & the x86 versions of all listed below on Machine 1 now.)
Microsoft Visual Studio C++ Version 2005 Redistributable (MFC Security Update)
Version 2008 (Ver 9.0.30729.6161)
Version 2010 (Ver 10.0.40219)
Version 2013 (Ver 12.0.40664)
Version 2015-2022 (Ver 14.31.31103)
All of these version were still available from Microsoft on March 16, 2022.