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

windows: making library loading work after SetDefaultDllDirectories() call (#1413) #1614

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/com/sun/jna/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@ Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType,
}

private static final int DEFAULT_OPEN_OPTIONS = -1;
private static int openFlags(Map<String, ?> options) {
private static final int DEFAULT_WINDOWS_RELATIVE_PATH_OPEN_OPTIONS = 0;
private static int openFlags(Map<String, ?> options, boolean isAbsolutePath) {
Object opt = options.get(Library.OPTION_OPEN_FLAGS);
if (opt instanceof Number) {
return ((Number)opt).intValue();
}
if (Platform.isWindows() && !isAbsolutePath) {
return DEFAULT_WINDOWS_RELATIVE_PATH_OPEN_OPTIONS;
}
return DEFAULT_OPEN_OPTIONS;
}

Expand All @@ -178,7 +182,7 @@ private static NativeLibrary loadLibrary(final String libraryName, final Map<Str
List<Throwable> exceptions = new ArrayList<>();
boolean isAbsolutePath = new File(libraryName).isAbsolute();
LinkedHashSet<String> searchPath = new LinkedHashSet<>();
int openFlags = openFlags(options);
int openFlags = openFlags(options, isAbsolutePath);

//
// Prepend any custom search paths specifically for this library
Expand Down Expand Up @@ -475,7 +479,7 @@ public static final NativeLibrary getInstance(String libraryName, Map<String, ?>

if (library == null) {
if (libraryName == null) {
library = new NativeLibrary("<process>", null, Native.open(null, openFlags(options)), options);
library = new NativeLibrary("<process>", null, Native.open(null, openFlags(options, true)), options);
}
else {
library = loadLibrary(libraryName, options);
Expand Down
Loading