Skip to content

Commit

Permalink
windows: making library loading work after `SetDefaultDllDirectories(…
Browse files Browse the repository at this point in the history
…)` call (#1413)
  • Loading branch information
trespasserw committed Jul 2, 2024
1 parent 4f94c57 commit b1066a1
Showing 1 changed file with 7 additions and 3 deletions.
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

0 comments on commit b1066a1

Please sign in to comment.