一、 工作环境
1. windows (64位), JDK (64位),dll文件 (64位)
2. Linux (64位), JDK (64位),so文件 (64位)
3. JNA的官方资源路径为https://github.com/twall/jna/
二、 实际操作
1.在cf.h头文件有如下申明:采用C语言形式接口函数
<span style="font-size:14px;">extern "C"
{
int Test(const char * first_name);
}</span>
2. Java调用代码:接口GlobalJnaLibrary.java
<span style="font-size:14px;">package cn.test;
import com.sun.jna.Library;
import com.sun.jna.Native;
public interface GlobalJnaLibrary extends Library {
GlobalJnaLibrary library = (GlobalJnaLibrary)Native.loadLibrary("TestGlobalVariable", GlobalJnaLibrary.class);
int Test(String first_name);
}</span>
3. 测试调用:GlobalJnaLibraryTes
.javapackage cn.test;
public class GlobalJnaLibraryTest {
public static void main(String[] args) {
int test = GlobalJnaLibrary.library.Test(new String("aaaa"));
System.out.println("test:"+test);
}
}
收尾: 请继续关注,或关注我的新浪微博:微博Abel