jni
类似c#调用c++的方式,定义java端的c++代码接口。
package crayon.jni; public class JNITest { public native static void set(int i); public native static int get(); static{ System.loadLibrary("JNITest"); } }
jna
jna是jni的封装,可以直接写c++代码(导入java的c头文件),再通过java调用,jna没有jni效率高。
#ifdef JNATEST_EXPORTS #define JNATEST_API __declspec(dllexport) #else #define JNATEST_API __declspec(dllimport) #endif extern "C" { JNATEST_API void set(long l); JNATEST_API long get(); } #include "stdafx.h" #include "JNATest.h" long tmp; JNATEST_API void set(long l){ tmp = l; } JNATEST_API long get(){ return tmp; }
import com.sun.jna.Library; import com.sun.jna.Native; public interface JNATest extends Library { JNATest INSTANCE = (JNATest) Native.loadLibrary( "D:/CC/Tools_Tool_ITT_StdPrj_Dev/PF_Tools_VOB/Tools_SubTool/src/JNATest/Release/JNATest", JNATest.class); public void set(int i); public int get(); }
jnative
jnative也是基于jni的封装,jnative可以不定义任何函数,通过反射的方式调用c++函数
JNative native = new JNative(“a.dll”,“get_value”);标签:调用,java,c++,public,jna,API,JNATest,JNATEST From: https://www.cnblogs.com/q-q56731526/p/17163076.html