我不得不这样做一会儿前。你需要一个C编译器和Windows头文件。我使用了mingw,因为它是免费的,我只编译一个小文件。
首先你要上你的课。这里有一个例子:
package org.whatever.thingy;
public class MyClass {
// Here is a JNI method, identified by 'native'
public static native callWin32Thingy(int x, int y, boolean z);
/* At this point, normal class stuff, other methods, variables, whatever */
}
你然后用自带的JDK中的命令,它会自动把你的类,并生成h和.c文件之一。该命令是“javah”。方法签名将如下所示:
JNIEXPORT void JNICALL Java_com_whatever_1thingy_MyClass_callWin32Thingy
(JNIEnv *, jclass, jint, jint, jboolean);
在.c文件中,可以包含任何需要的窗口标头,并充实该方法。
JNIEXPORT void JNICALL Java_com_whatever_1thingy_MyClass_callWin32Thingy
(JNIEnv *a, jclass b, jint c, jint d, jboolean e) {
// Prep steps....
Win32MethodCallWeCareAbout(x, y, z, hWhatever);
// Cleanup stuff...