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"

解决方案 »

  1.   

    你要加上-Djava.library.path=参数,并且你要知道Win32 3大DLL在Windows/System32下。
      

  2.   

    public class TestJni { public native String  GetTickCount();
    static {
    System.loadLibrary("Kernel32");
    }
    public static void main(String[] args) {
    TestJni testJni = new TestJni();
    testJni.GetTickCount();
    }
    }
    GetTickCount()是windowsapi函数,我在java里调用它,如何表示它的返回类型WINAPI 那?
      

  3.   

    上面代码执行的异常是
    Exception in thread "main" java.lang.UnsatisfiedLinkError: GetTickCount
    at TestJni.GetTickCount(Native Method)
    at TestJni.main(TestJni.java:11)
      

  4.   

    WINAPI是一个宏,这个是你可以忽略的东西,关于它要讲的东西涉及到栈和汇编,对Java来说没有用处。
    你知道知道能被Java调用的C函数,一定是被WINAPI修饰的就可以了,它实际是__stdcall,就是C,C++,VB,Pascal共同遵守的调用规则。
      

  5.   

    Windows API 不能从java直接调用,不用折腾了。
    JNI是要写本地代码的,在本地代码里才能调用Windows API