今天学习Java看到Jni部分, 终于看到Java如何调用其他语言写的函数(我期待已久了….
:P)
下面把过程写下来,免得以后忘了又要是处找资料.
首先是Java写的测试类
public class TestJni
{
native void SetMouseRangle(int left, int right, int top, int bottom);
static{
System.loadLibrary("TestJni");
}
public static void main(String []args){
TestJni test = new TestJni();
test.SetMouseRangle(0,0,0,0);
test.SetMouseRangle(100,100,200,200);
}
}
SetMouseRangle用它来代替同名的本地函数,它的前面必须要有native关键字,而且它不能有函数体.这个函数是为了指定一个矩形的范围,把鼠标限定在这个矩形里面5秒钟.
static{