How to pass C structs back and forth to Java code in JNI?

后端 未结 4 1932
一向
一向 2020-11-27 10:58

I\'ve got some C functions which I am calling through JNI which take a pointer to a structure, and some other functions which will allocate/free a pointer to the same type o

4条回答
  •  攒了一身酷
    2020-11-27 11:51

    You need to create a Java class with the same members as C struct, and 'map' them in the C code via methods env->GetIntField, env->SetIntField, env->GetFloatField, env->SetFloatField, and so on - in short, lots of manual labor, hopefully there already exist programs that do it automatically: JNAerator (http://code.google.com/p/jnaerator) and SWIG (http://www.swig.org/). Both have their pros and cons, the choice is up to you.

提交回复
热议问题