forked from tianshb/JavaLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJNAPointer.java
More file actions
45 lines (37 loc) · 1.1 KB
/
Copy pathJNAPointer.java
File metadata and controls
45 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import com.sun.jna.*;
import com.sun.jna.ptr.*;
public class JNAPointer {
/**
* @param args
*/
public interface CLib extends Library{
public interface OpenFunc extends Callback{
void invoke ( IntByReference p1);
//void invoke(String filename , int i);
}
public class FunCallBack implements OpenFunc{
@Override
/*public void invoke(String filename , int i){
System.out.println("callback called.");
System.out.println(filename);
}*/
public void invoke( IntByReference p1){
System.out.println(p1);
System.out.println("callback called.");
}
}
void init(OpenFunc openfunc);
void swap( IntByReference p1 , IntByReference p2);
void test();
}
public static void main(String[] args) {
CLib lib =(CLib)Native.loadLibrary("JNALib", CLib.class);
CLib lib2 = (CLib)Native.loadLibrary("swap",CLib.class);
CLib.FunCallBack func = new CLib.FunCallBack();
IntByReference p1 = new IntByReference (3);
IntByReference p2 = new IntByReference (5);
lib.init( func);
lib2.swap(p1, p2);//Java called C++ pointer
lib.test();//C++ callback java
}
}