win7 java jna找不到,JNA无法找到通过Java dll文件规定的程序

I am trying to access dll procedure through java but my java method is unable to find the procedure. The dll file is loaded successfully but the the procedure from C# code named Login I can't call.

Below is the def of Procedure in ADHelper.dll:

public static ADHelper.LoginResult Login(string UserName, string Password)

{

if (!ADHelper.IsUserValid(UserName, Password))

return ADHelper.LoginResult.LOGIN_USER_DOESNT_EXIST;

DirectoryEntry user = ADHelper.GetUser(UserName);

if (user == null)

return ADHelper.LoginResult.LOGIN_USER_DOESNT_EXIST;

int userAccountControl = Convert.ToInt32(RuntimeHelpers.GetObjectValue(user.Properties["userAccountControl"][0]));

user.Close();

return !ADHelper.IsAccountActive(userAccountControl) ? ADHelper.LoginResult.LOGIN_USER_ACCOUNT_INACTIVE : ADHelper.LoginResult.LOGIN_OK;

}

The dll file name is ADHelper.dll. The LoginResult is enum type:

public enum LoginResult

{

LOGIN_OK,

LOGIN_USER_DOESNT_EXIST,

LOGIN_USER_ACCOUNT_INACTIVE,

}

Below is my java program to normally call the procedure:

package dllTest;

import com.sun.jna.*;

public class DllTester {

public interface ADHelper extends Library {

public final int LOGIN_OK=1;

public final int LOGIN_USER_DOESNT_EXIST=2;

public final int LOGIN_USER_ACCOUNT_INACTIVE=3;

public int Login(String user, String pass);

}

public static void main(String[] args) {

ADHelper objADH = (ADHelper) Native.loadLibrary("ADHelper", ADHelper.class);

System.out.println(objADH.getClass().getDeclaredMethods());

objADH.Login("ashish", "asdas");

}

}

Now, it is gives following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error

looking up function 'Login': The specified procedure could not be

found.

Do tell me if any more details are needed.

The solution is based upon this methodolgy:

NOTE: I have included the dll file in system32 for testing purpose, as for easy access too. the dll file is loading but the Login function is not calling.

The output of SOP line in java is :

[Ljava.lang.reflect.Method;@145d068

解决方案

The problem here is that your DLL is a .Net DLL, which is not a native DLL. JNA only loads and understands native DLLs, that is, DLLs built to function outside the .Net framework.

What this means is that you need a different glue between Java and .Net. I have successfully worked with Jni4net and IKVM, and there are a few others, you might want to look at those.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值