我想在java中加载dll文件并调用dll方法。试过2个变种:loadLibrary&在windows中注册dll。不幸的是,两者对我都不起作用。
使用System.loadLibrary:
public class App {
static {
try {
System.loadLibrary("abc");
System.loadLibrary("xyz");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static native double gamma(double x);
public static void main(String[] args) {
new App().gamma(10.1);
}
在运行上述程序时我遇到了异常。
Exception in thread "main" java.lang.UnsatisfiedLinkError: App.gamma(D)D
at App.gamma(Native Method)
at App.main(App.java:26)
尝试使用regsvr32注册dll文件并在java中获取访问权限。
C:\Windows\System32>regsvr32 /in abc.dll
C:\Windows\System32>regsvr32 /in xyz.dll
如果我在cmd中输入上述命令,我收到以下消息。 已加载模块“D:\ abc.dll”但未找到入口点DllRegisterServer。
而且,在这种情况下,不知道如何在java中访问系统注册的dll方法。