This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients aeros, eryksun, miss-islington, paul.moore, steve.dower, tim.golden, vstinner, xtreak, zach.ware
Date 2020-04-13.18:44:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586803495.06.0.195541453007.issue40214@roundup.psfhosted.org>
In-reply-to
Content
> it seems the search order we're getting for _sqlite3.dll (.pyd) is:
>
> * app directory
> * SQL server install directory (?)
> * Windows/System32
> * Windows
> * %PATH% (which is truncated at 2190 chars)

Thank you. It finally makes sense. The parent process is calling SetDllDirectoryW [1], which also replaces the current working directory in the DLL search path of child processes (inherited via the PEB ProcessParameters->DllPath) [2]: 

    Note: The standard search order of the process will also be 
    affected by calling the SetDllDirectory function in the parent
    process before start of the current process.

In that case, all we have to do is restore the original search path by calling SetDllDirectoryW(NULL). For example:

    import ctypes
    kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
    if not kernel32.SetDllDirectoryW(None):
        raise ctypes.WinError(ctypes.get_last_error())


[1]: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectoryw
[2]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#alternate-search-order-for-desktop-applications
History
Date User Action Args
2020-04-13 18:44:55eryksunsetrecipients: + eryksun, paul.moore, vstinner, tim.golden, zach.ware, steve.dower, miss-islington, xtreak, aeros
2020-04-13 18:44:55eryksunsetmessageid: <1586803495.06.0.195541453007.issue40214@roundup.psfhosted.org>
2020-04-13 18:44:55eryksunlinkissue40214 messages
2020-04-13 18:44:54eryksuncreate