Native library is unable to load the DLL under Java 7

650 views
Skip to first unread message

Trevor Maggs

unread,
Feb 22, 2021, 7:38:20 PM2/22/21
to Java Native Access
I will try to be brief and simple to the point.

My Java project is designed to run on Java 7 and Java 8, more specifically, at least Java 7. It works very well both on Linux and Windows. My main development platform is Windows 10 and RHEL 8 with the latest version of Eclipse running on Java 8.

My objective is for the program to be able to run on at least Windows Server 2003 to collect some security related information. To do this, it copies both 32bit and 64bit DLLs from the jar file to the temporary folder using `System.getProperty("java.io.tmpdir")`.

Everything is working well on Windows 10 and Java 8 JDK with JNA 5.5.0.

Recently, I set up a test platform running Windows 2003 R2 (64 bit) with Java 7u80. The code was compiled without issue, but when running, I see this strange error message (truncated).

`Unable to load library 'C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\1\jnalfx64.dll':
The specified procedure could not be found.
The specified procedure could not be found.
Native library (win32-x86-64/C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\1\jnalfx64.dll) not found in resource path ([file:/C:/domains/win2003/class/, file:/C:/domains/win2003/lib/commons-collections4-4.1.jar, file:/C:/domains/win2003/lib/jna-5.5.0.jar, file:/C:/domains/win2003/lib/jna-platform-5.5.0.jar, file:/C:/domains/win2003/lib/poi-3.17.jar, file:/C:/domains/win2003/lib/poi-ooxml-3.17.jar, file:/C:/domains/win2003/lib/poi-ooxml-schemas-3.17.jar, file:/C:/domains/win2003/lib/xmlbeans-2.6.0.jar])`

I double-checked the DLL and it is always there (C:\Documents and Settings\Administrator\Local Settings\Temp\1\jnalfx64.dll) again and again. 

Here is the code in question.

`SAMSecurityPolicyNative INSTANCE = Native.load(Scanner.getWinLibraryDLL(), SAMSecurityPolicyNative.class, W32APIOptions.UNICODE_OPTIONS);`
.
.
.
`    Under Scanner class:
public static String getWinLibraryDLL()
    {
        // Called by JNA activated classes only
        return (winLibraryFileDLL == null) ? "" : winLibraryFileDLL.toAbsolutePath().toString();
    }
`
Like I said, the program should work on Java 7 and later. Is there something I am missing out or maybe I never knew something that I was supposed to do to make it right? Anyone has any idea?

Trevor



Matthias Bläsing

unread,
Feb 23, 2021, 12:32:30 PM2/23/21
to jna-...@googlegroups.com
Hi Trevor,

check the dependencies of your DLL. I'd bet, that it depends on a dll,
that comes with Java 8 bundled, but is not present on Java 7.

Greetings

Matthias
> --
> 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/a3fecf0a-17e9-4879-950c-5b9d5cfe1560n%40googlegroups.com
> .


Trevor Maggs

unread,
Feb 23, 2021, 4:15:33 PM2/23/21
to Java Native Access
Hi Matthias,

What do you mean by dependencies on a DLL? I created the DLL myself with Microsoft Visual Studio code which is designed to work on Windows platforms only. Nothing to do with Java. The problem I am seeing on Windows 2003 is related to JVM not being able to find the DLL even though it is there?

The DLL is small which I developed to provide information I want so it’s easier for Java to retrieve information through JNA. That’s all.

So your question brought some attention to me. I was wondering if the error message “The specified procedure could not be found“ means the JVM did find the DLL but could not call some C functions inside the DLL due to incompatible dependencies on Windows 2003? Is that what you meant?

Trevor

Matthias Bläsing

unread,
Feb 23, 2021, 4:27:15 PM2/23/21
to jna-...@googlegroups.com
Hi Trevor,

Am Dienstag, den 23.02.2021, 13:15 -0800 schrieb Trevor Maggs:
>
> What do you mean by dependencies on a DLL? I created the DLL myself
> with Microsoft Visual Studio code which is designed to work on
> Windows platforms only. Nothing to do with Java. The problem I am
> seeing on Windows 2003 is related to JVM not being able to find the
> DLL even though it is there?

You used Visual Studio, so most probably the DLL is not self contained,
but linked against the visual C++ runtime. If that runtime is not
present on the target system, your DLL can't be loaded because the
runtime can't be loaded.

Use dependency walker to see if all your dependencies are present.

> The DLL is small which I developed to provide information I want so
> it’s easier for Java to retrieve information through JNA. That’s all.

My advise: Adding another intermedia is at most times not helpful. I
would try to depend on a as small as possible number of dependencies
and only relying on libjnidispatch (the native JNA part) and the system
libraries would be _my_ preferred option.

So your question brought some attention to me. I was wondering if the >
error message “The specified procedure could not be found“ means the >
JVM did find the DLL but could not call some C functions inside the >
> DLL due to incompatible dependencies on Windows 2003? Is that what 
> you meant?

Maybe, this stack overflow questions might help:

https://stackoverflow.com/questions/8908112/the-specified-procedure-could-not-be-found-error-when-running-app-on-windows-x

Greetings

Matthias

Daniel Widdis

unread,
Feb 24, 2021, 1:25:47 AM2/24/21
to jna-...@googlegroups.com

Trevor,

 

You have indicated that you changed both the Windows version and JDK version (Win 2003 + JDK7 and Win10 + JDK8).

 

Are you sure the problem relates to the JDK and not the Windows version?  2003 is XP-based and a vast majority of DLLs are Vista+/Server 2008+.

 

The error message does suggest a problem loading a dependency of your DLL which may not exist (or has fewer/different functions/structures/etc.) on Server 2003.

 

Dan

Trevor Maggs

unread,
Feb 24, 2021, 1:44:08 AM2/24/21
to Java Native Access
Hi Dan and Matthias,

Yes, after taking Matthias's comments into consideration, I can confirm the problem relates to the DLL part not JDK. The problem is that 5 Win32 API functions I used for the DLL are designed for Windows Server 2008+.

In other words, Windows 2003 is very old and not all Win32 functions are supported, therefore my issue is the dependency problem. The dependency walker tool showed 5 functions are unsupported on Windows 2003. I am going to add some workout solutions to circumvent that and test again. My aim is to make the DLL work on Windows 2003+.

Trevor

Reply all
Reply to author
Forward
0 new messages