Dll invokes another dll with JNA

Let me try to explain my problem.

I have the following directory structure:

  • main directory
    • CSI
    • vn
    • Ben

Today the DLLs are inside the bin folder and work fine, but due to the requirement I need to go to the ext folder.

When the application starts, I install jna.library.path and java.library.path at runtime:

// JNA
    System.setProperty("jna.library.path", myLibraryPath); 

and

// JAVA
final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);

final String[] paths = (String[])usrPathsField.get(null);

for(String path : paths) {
    if(path.equals(libraryPath)) {
        return;
    }
}

final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[newPaths.length-1] = libraryPath;
usrPathsField.set(null, newPaths);

The above code sets java.library.path after initialization.

I tried running it also on the command line:

-Djna.library.path=path_to_ext -Djava.library.path=path_to_ext

So, in my tests, I found that the problem occurs when I call a method from a dll, and this method calls another method of a different dll.

Can someone help me?

Thank you so much

0
source share
1

, HKEY_CURRENT_USER/Environment/Path myLibraryPath.

0

Source: https://habr.com/ru/post/1546377/


All Articles