我在java中写了如下的函数:
class MyJniTest()
{
public native void ShowHello();
public static main()
{
System.out.print("begin\n");
new MyJniTest().ShowHello();
System.out.print("end\n");
}
}
//在c++中的函数如下
JNIEXPORT void JNICALL Java_MyJniTest_ShowHello
(JNIEnv *, jobject)
{
printf("hello\n");
}
//但是执行结果确是:
begin
end
hello
hello 应该在begin 和 end 之间但确跑到最后去了,为什么?
class MyJniTest()
{
public native void ShowHello();
public static main()
{
System.out.print("begin\n");
new MyJniTest().ShowHello();
System.out.print("end\n");
}
}
//在c++中的函数如下
JNIEXPORT void JNICALL Java_MyJniTest_ShowHello
(JNIEnv *, jobject)
{
printf("hello\n");
}
//但是执行结果确是:
begin
end
hello
hello 应该在begin 和 end 之间但确跑到最后去了,为什么?
class MyJniTest()
{
public native void ShowHello(); static
{
System.LoadLLibrary("hello");
}
public static main()
{
System.out.print("begin\n");
new MyJniTest().ShowHello();
System.out.print("end\n");
}
}
System.loadLibrary("hello"); // hello.dll的文件名
} public native void ShowHello(); public static main(){
System.out.print("begin\n");
new MyJniTest().ShowHello();
System.out.print("end\n");
}}
你让native返回一个jstring就会发现是立即执行的