Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change dll search path? #97

Open
nstbayless opened this issue Apr 24, 2023 · 2 comments
Open

How to change dll search path? #97

nstbayless opened this issue Apr 24, 2023 · 2 comments

Comments

@nstbayless
Copy link

I want to load a dll /path/to/library.dll, but I'm working directory /some/other/path. This is okay, unless library.dll requires /path/to/dependency.dll, in which case it doesn't load at all.

This works:

os.chdir("/path/to/")
import zugbruecke.ctypes as ctypes
ctypes.windll.LoadLibrary("library.dll")

However, this does not work (!):

import zugbruecke.ctypes as ctypes
os.chdir("/path/to/")
ctypes.windll.LoadLibrary("library.dll")

-- It results in an an OSError. As do the following:

os.environ["PATH"] += ":/path/to"
import zugbruecke.ctypes as ctypes
ctypes.windll.LoadLibrary("library.dll")
import zugbruecke.ctypes as ctypes
k32 = ctypes.windll.LoadLibrary("kernel32.dll")
k32.SetDllDirectoryA.argtypes = [ctypes.c_char_p]
k32.SetDllDirectoryA.restype = ctypes.c_int
k32.SetDllDirectoryA.memsync = [dict(pointer=[0], null=True)]
k32.SetDllDirectoryA("/path/to")
ctypes.windll.LoadLibrary("library.dll")

export PATH="$PATH:/path/to" before running this script also results in an OSError.

The solution I found only partially works. Ideally, I don't want to have to change the working directory (those DLL's won't be able to load files as expected, I think?). Also, it doesn't work if I want to load DLL's from multiple paths.

@nstbayless
Copy link
Author

Resolved: os.environ["WINEPATH"]="/path/to" works.

@nstbayless
Copy link
Author

Actually -- it would be nice to be able to edit the dll search path after importing zugbruecke, which os.environ["WINEPATH"]="/path/to" doesn't do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants