public class Test2 {
static
{
System.loadLibrary("kernel32");
}
public native static void GetWindowsDirectory(String temp,int length);
public Test2()
{
}
public static void main(String[] args) {
String sysroot="";
int length=50;
Test2 t=new Test2();
System.out.println(System.getProperty("java.library.path"));
t.GetWindowsDirectory(sysroot,50);
System.out.println(sysroot);
}
}
输出的java.library.path为“E:\JBuilder9\jdk1.4\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem”
这里直接调用的是C:\WINDOWS\system32目录下的kernel32.dll的GetWindowsDirectory方法,但执行时报错为
java.lang.UnsatisfiedLinkError: GetWindowsDirectory
at cn.edu.sdu.tavor.Test2.GetWindowsDirectory(Native Method)
at cn.edu.sdu.tavor.Test2.main(Test2.java:28)
Exception in thread "main"
请问为什么,应该如何做才行呢?是不是要自己写一个dll,在其中调用GetWindowsDirectory方法,然后在JAVA中再调用这个dll?最好能给个例子,谢谢!
static
{
System.loadLibrary("kernel32");
}
public native static void GetWindowsDirectory(String temp,int length);
public Test2()
{
}
public static void main(String[] args) {
String sysroot="";
int length=50;
Test2 t=new Test2();
System.out.println(System.getProperty("java.library.path"));
t.GetWindowsDirectory(sysroot,50);
System.out.println(sysroot);
}
}
输出的java.library.path为“E:\JBuilder9\jdk1.4\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem”
这里直接调用的是C:\WINDOWS\system32目录下的kernel32.dll的GetWindowsDirectory方法,但执行时报错为
java.lang.UnsatisfiedLinkError: GetWindowsDirectory
at cn.edu.sdu.tavor.Test2.GetWindowsDirectory(Native Method)
at cn.edu.sdu.tavor.Test2.main(Test2.java:28)
Exception in thread "main"
请问为什么,应该如何做才行呢?是不是要自己写一个dll,在其中调用GetWindowsDirectory方法,然后在JAVA中再调用这个dll?最好能给个例子,谢谢!
再详细点好吗?最好给出代码来,谢谢了。