Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a structure as an argument to java function or return to java from jni

I have two questions Say I have some structure in jni say

struct X
{
    Type_A x;
    Type_B y;
}

Now how do I?

  1. Pass this structure as an argument to a java call back function
  2. How do I return this structure to a Java function.

If possible, please give an example.

like image 961
Prabhu Konchada Avatar asked Oct 19 '22 12:10

Prabhu Konchada


1 Answers

Java Native Access handles the details automatically (in addition to avoiding the native compilation step entirely).

public class MyStructure extends com.sun.jna.Structure {
    public int x;
    public int y;
}

It also supports nested types, so you can have structures, pointers, or even unions as fields within the structure.

like image 68
technomage Avatar answered Nov 01 '22 11:11

technomage