0

I want to understand how does the

 "self._handle = _dlopen(self._name, mode)"

in ctypes__ inits____ work, if the

self.name = "path/xxx.dll" 

and that self.name dll needs additional dll, where should be the additional dll be placed and how to know which dll is missing.

朱嘉诚
  • 39
  • 5
  • This [answer](https://stackoverflow.com/a/23805306/205580) provides several ways to extend/modify the legacy DLL search path prior to Python 3.8. I prefer `LOAD_WITH_ALTERED_SEARCH_PATH` since it only modifies the search path for the current call. – Eryk Sun May 22 '19 at 11:48
  • In 3.8, there's a new [`winmode` parameter](https://docs.python.org/3.8/library/ctypes.html#ctypes.CDLL) to pass custom Windows `LoadLibraryEx` flags. Also, now ctypes implicitly loads dependent DLLs from a *qualified* target DLL directory, like `LOAD_WITH_ALTERED_SEARCH_PATH` but using the new `LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR` flag that's available in updated Windows 7 systems. There's also a new [`os.add_dll_directory`](https://docs.python.org/3.8/library/os.html#os.add_dll_directory) context manager to extend the process DLL search path, because `PATH` is no longer used by default. – Eryk Sun May 22 '19 at 11:49
  • Thank you , And how to know where the requiring dll is and which one is missing"if have an error", now it has an error and I don't know which requiring one is missing nor where all the dll is – 朱嘉诚 May 22 '19 at 20:40
  • One way to find the missing DLL(s) is to use Sysinternals [Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) with filters that log `IRP_MJ_CREATE` (file open) operations where the path contains ".DLL" and the process is "python.exe". Look for where it first loads the target DLL and then for a subsequent run of operations where the result is "NAME NOT FOUND". This is the loader looking for and failing to find a dependent DLL. – Eryk Sun May 23 '19 at 00:02
  • Apparently I can't @ target 朱嘉诚, at the start of a message in Firefox. It gets removed automatically. – Eryk Sun May 23 '19 at 00:04

0 Answers0