loadNativeDispatchLibraryFromClasspath loads wrong jna-dll

12 views
Skip to first unread message

Bo Vidar Göran Lundgren

unread,
May 3, 2024, 3:54:28 AMMay 3
to Java Native Access
On a customer site the call at com.sun.jna.platform.win32.Advapi32Util.registryKeyExists(Advapi32Util.java:607 will load C:\Users\mime502\AppData\Local\Temp\jna-1063439427\jna1460056660941337611.dll which is a dll installed by the customer and obviously not part of net.java.dev.jna. As I understand the jnidispatch.dll should be called. 

The net.java.dev.jna is used in an application to retrieve values from the Windows registry. 
Customer platform is Windows 10
Java version in application is Amazon Coretto 1.8.0_265

Neil C Smith

unread,
May 3, 2024, 5:49:25 AMMay 3
to jna-...@googlegroups.com
That is the native library automatically extracted from the JNA JAR
file. To control how this works, or to use a pre-extracted native
library, take a look at the documentation at
https://javadoc.io/static/net.java.dev.jna/jna/5.14.0/com/sun/jna/Native.html

Best wishes,

Neil


--
Neil C Smith
Codelerity Ltd.
www.codelerity.com

Codelerity Ltd. is a company registered in England and Wales
Registered company number : 12063669
Registered office address : 3rd Floor Suite, 207 Regent Street,
London, W1B 3HH, England

Bo Vidar Göran Lundgren

unread,
May 28, 2024, 9:23:12 AMMay 28
to Java Native Access

Hi Neil thanks for you answer but I am still confused,  when I install the application the DLL is not extracted. They seem to have a group policy that permits the usage - do you know how I can get around this ? 

Daniel B. Widdis

unread,
May 28, 2024, 12:56:15 PMMay 28
to jna-...@googlegroups.com
When the JNA library path is not specified and it's not present in any of the expected locations described in the javadoc, JNA extracts that DLL from the class path, and then saves it to a temporary location.  The code where it's saved to a temp file like the one you've shown is here:  https://github.com/java-native-access/jna/blob/40f0a1249b5ad03020b5a2b66f42b9546e6d4edf/src/com/sun/jna/Native.java#L1165-L1184

As you can see in that code block, you can set jnidispatch.preserve to automatically delete that temp file on (clean) exit (in OpenJDK, at least.)

As Neil said, the best way to prevent this is to pre-extract the library and save it in a known location that you make sure is available to JNA when it starts up.  Then it will never get to this temp file path.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/0eb54e3a-d3d7-499e-ba63-5e04890ba1d2n%40googlegroups.com.


--
Dan Widdis

Neil C Smith

unread,
May 28, 2024, 3:04:54 PMMay 28
to jna-...@googlegroups.com
On Tue, 28 May 2024 at 17:56, Daniel B. Widdis <wid...@gmail.com> wrote:
> As Neil said, the best way to prevent this is to pre-extract the library and save it in a known location that you make sure is available to JNA when it starts up. Then it will never get to this temp file path.

The following link is also possibly more useful and current than the
one I shared before, which doesn't seem to cover current default
behaviour - https://javadoc.io/static/net.java.dev.jna/jna/5.14.0/overview-summary.html#loading
Reply all
Reply to author
Forward
0 new messages