解压JNative-1.3.2.zip 获得三个文件,分别是:JNativeCpp.dll,libJNativeCpp.so,JNative.jar 。JNativeCpp.dll Windows下用的,拷到windows / system32目录下;
libJNativeCpp.so Linux下使用的;
JNative.jar 这是一个扩展包,加载到你的程序中就可以。
一个简单例子
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.exceptions.NativeException;
public class JNativeTest {
public static final int messageBox(int parentHandle, String message,
String caption, int buttons){// throws NativeException, IllegalAccessException {
JNative n = null;
try {
n = new JNative("User32.dll", "MessageBoxA"); //“.dll”不用也可以, 常量DLL_NAME的值为User32.dll
// 构造JNative时完成装载User32.dll,并且定位MessageBoxA方法
n.setRetVal(Type.INT); // 指定返回参数的类型
int i = 0;
n.setParameter(i++, Type.INT, "" + parentHandle);
n.setParameter(i++, Type.STRING, message);
n.setParameter(i++, Type.STRING, caption);
n.setParameter(i++, Type.INT, "" + buttons); // 指定位置上的参数类型和值
n.invoke(); // 调用方法
return Integer.parseInt(n.getRetVal());
}
catch(Exception ex){
ex.printStackTrace();
}
finally {
if (n != null)
try {