public class TestJni { public native void GetTickCount();
static {
System.loadLibrary("Kernel32.dll");
}
public static void main(String[] args) {
TestJni testJni = new TestJni();
testJni.GetTickCount();
}
}
执行上面代码结果是,我想用java调用windowsAPI
java.lang.UnsatisfiedLinkError: no Kernel32.dll in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.TestJni.<clinit>(TestJni.java:7)
Exception in thread "main"
static {
System.loadLibrary("Kernel32.dll");
}
public static void main(String[] args) {
TestJni testJni = new TestJni();
testJni.GetTickCount();
}
}
执行上面代码结果是,我想用java调用windowsAPI
java.lang.UnsatisfiedLinkError: no Kernel32.dll in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.TestJni.<clinit>(TestJni.java:7)
Exception in thread "main"
static {
System.loadLibrary("Kernel32");
}
public static void main(String[] args) {
TestJni testJni = new TestJni();
testJni.GetTickCount();
}
}
GetTickCount()是windowsapi函数,我在java里调用它,如何表示它的返回类型WINAPI 那?
Exception in thread "main" java.lang.UnsatisfiedLinkError: GetTickCount
at TestJni.GetTickCount(Native Method)
at TestJni.main(TestJni.java:11)
你知道知道能被Java调用的C函数,一定是被WINAPI修饰的就可以了,它实际是__stdcall,就是C,C++,VB,Pascal共同遵守的调用规则。
JNI是要写本地代码的,在本地代码里才能调用Windows API