Click here to Skip to main content
13,661,044 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am getting this issue of UnsatisfiedLink on calling this native Function
Pls. help me
Below is my code
import com.sun.jna.ptr.*;
class Test1
	IntByReference lToken=null; 
        System.out.println("Before loading advapi32.dll");
        System.out.println("After loading advapi32.dll");
    public static void main(String ar[])
        System.out.println("Hello world from Java");
        Test1 t=new Test1();	


        // t.inDll();
//   public native void inDll();
     public  native static boolean LogonUser(String sUserName,String 

sDomainName, String sPassword,int LOGON32_LOGON_NETWRK,int 

LOGON32_PROVIDER_DEFAULT,IntByReference lToken);
Posted 2-Dec-09 1:26am
Updated 21-Aug-17 12:07pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Looking at the JNA Documentation[^], I cannot see a direct reference for LogonUser(). I suspect you will need to use an alternative method to get the address of the function, possibly the W32APIFunctionMapper class.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi Manoj,

I am also looking for JNA solution to authenticate the windows NT credientials. When I execute the following program, I am getting unsatisfiedLinkerror. I have added the jna.jar file in the windows CLASSPATH. Have you got a solution for your problem, if please provide me the code. I am using Apache tomcat and windows XP server.

import com.sun.jna.Library;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/** Simple example of JNA interface mapping and usage. */
public class HelloWorld {

//    static {
//    	System.load("C:\\Windows\\system32\\advapi32.dll"); 
//    }
	// This is the standard, stable way of mapping, which supports extensive
    // customization and mapping of Java to native types.
    public interface CLibrary extends StdCallLibrary {
       CLibrary INSTANCE = (CLibrary)
	  Native.loadLibrary((Platform.isWindows() ? "advapi32" : "c"),  CLibrary.class);
       public boolean LogonUser(String userName, String domain,String password, int dwLogonType, int dwLogonProvider, IntByReference lToken);

    public static void main(String[] args) {
    	IntByReference lToken=null;  	

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hi - I realize this post is about two years old, but for those that may be looking at a similar issue - I had a similar issue yesterday, and the answers via Google I found were kind of obtuse.
It looks like in both cases the IntByReference object "lToken" has not been initialized. Set it before calling ...
lToken = new IntByReference();

After a successful login call the return value is "true" and the lToken object will have the token info, for failed login ("false"), the object is not changed.

For the failed-login cases you should code an jna/native instance of "Kernel32" so you can call "GetLastError()" method. This is because the un/pw may be correct, but there will be other reasons to fail. One example is "Not authorized on this machine".
( i.e. some of the codes from microsoft )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05-2016 | 2.8.180810.1 | Last Updated 21 Aug 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100