Java-C connection works
Pointers can be passed freely
This commit is contained in:
parent
cc7cd15efa
commit
026edffed4
5 changed files with 37 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
libpxc.so
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
|
|
5
VirtualComputer/src/sznp/virtualcomputer/PXCLib.java
Normal file
5
VirtualComputer/src/sznp/virtualcomputer/PXCLib.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package sznp.virtualcomputer;
|
||||
|
||||
public interface PXCLib {
|
||||
int convert(int[] px, long[] out);
|
||||
}
|
19
VirtualComputer/src/sznp/virtualcomputer/Test.java
Normal file
19
VirtualComputer/src/sznp/virtualcomputer/Test.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package sznp.virtualcomputer;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import jnr.ffi.LibraryLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new File("").getAbsolutePath());
|
||||
PXCLib pxc = LibraryLoader.create(PXCLib.class).search(new File("").getAbsolutePath()).load("pxc");
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(2);
|
||||
long[] x = new long[]{Pointer.nativeValue(Native.getDirectBufferPointer(bb))};
|
||||
pxc.convert(new int[]{5, 10}, x);
|
||||
System.out.println(bb.get(0)); //19 AYY
|
||||
}
|
||||
}
|
|
@ -7,4 +7,5 @@ pxct: pxct.c pxc
|
|||
pxc: pxc.c
|
||||
$(CC) -Wall -c -fpic pxc.c -o obj/pxc.o
|
||||
$(CC) -Wall -shared obj/pxc.o -o out/libpxc.so
|
||||
cp out/libpxc.so ../
|
||||
|
||||
|
|
10
libpxc/pxc.c
10
libpxc/pxc.c
|
@ -1,7 +1,17 @@
|
|||
#include <stdio.h>
|
||||
|
||||
typedef long long int lli;
|
||||
|
||||
void* image=NULL;
|
||||
|
||||
void setSource(lli address) {
|
||||
image=(void*)address;
|
||||
}
|
||||
|
||||
int convert(int px[], int *out[]) {
|
||||
printf("convert...\n");
|
||||
printf("px0: %d\n", px[0]);
|
||||
*out[0]=19;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue