JNA 无法通过 java 在 dll 文件中找到指定的过程
JNA couldn't find the specified procedure in dll file through java
我试图通过 java 访问 dll 程序,但我的 java 方法无法找到该程序。 dll 文件已成功加载,但无法调用 C# 代码中名为 Login 的过程。
下面是ADHelper.dll中Procedure的定义:
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;
}
dll 文件名为 ADHelper.dll。 LoginResult 是枚举类型:
public enum LoginResult
{
LOGIN_OK,
LOGIN_USER_DOESNT_EXIST,
LOGIN_USER_ACCOUNT_INACTIVE,
}
下面是我的java正常调用程序的程序:
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");
}
}
现在,它给出了以下错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error
looking up function 'Login': The specified procedure could not be
found.
如果需要更多详细信息,请告诉我。
解决方案基于此方法:
enums/constants handling in java for dll.
注意:出于测试目的,我已将 dll 文件包含在 system32 中,以便于访问。 dll 文件正在加载,但登录功能未调用。
java 中 SOP 行的输出是:
[Ljava.lang.reflect.Method;@145d068
我试图通过 java 访问 dll 程序,但我的 java 方法无法找到该程序。 dll 文件已成功加载,但无法调用 C# 代码中名为 Login 的过程。
下面是ADHelper.dll中Procedure的定义:
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;
}
dll 文件名为 ADHelper.dll。 LoginResult 是枚举类型:
public enum LoginResult
{
LOGIN_OK,
LOGIN_USER_DOESNT_EXIST,
LOGIN_USER_ACCOUNT_INACTIVE,
}
下面是我的java正常调用程序的程序:
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");
}
}
现在,它给出了以下错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'Login': The specified procedure could not be found.
如果需要更多详细信息,请告诉我。
解决方案基于此方法:
enums/constants handling in java for dll.
注意:出于测试目的,我已将 dll 文件包含在 system32 中,以便于访问。 dll 文件正在加载,但登录功能未调用。
java 中 SOP 行的输出是:
[Ljava.lang.reflect.Method;@145d068