Python ctypes use winmode to load DLLs

2

I've installed an C++ API application which puts a couple of DLLs (A.DLL and B.DLL) in my programs folder. A.DLL has a dependency on B.DLL

I can load them successfully with ctypes.WinDLL IF from the installation folder like C:\Programs Files\XXX-API\A.DLL

while if I move the folder to another place C:\TEMP\ , the Python cytes load will complain that it can't find B.DLL.

I'm looking into the winmode, looks like it will solve the problem. The winmode seems to take an integer from parameters in MS reference .

for example :

LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

0x00000100

To use LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR ,to pass 0x00000100 as 256 to winmode ? ctype will complain can not find B.DLL,I'm not sure what's missing ,appreciate any idea from you ,thanks !

ctypes.WinDLL(path_to_A_DLL , winmode = 256 )
python
ctypes
asked on Stack Overflow Jan 9, 2020 by Shawn Zhang • edited Jun 20, 2020 by Community

1 Answer

1

Alternative 1:

import nt
_func1 = ctypes.WinDLL(lib_name, winmode = nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)

Alternative 2:

_func1 = ctypes.WinDLL(lib_name, winmode = 0x100)

Should both work.

But was trying os.add_dll_directory() all day long. Switched finally to

_func1 = ctypes.WinDLL(absolute_lib_path, winmode = 0x8)
answered on Stack Overflow Mar 17, 2020 by araisch

User contributions licensed under CC BY-SA 3.0