Yes, you can populate a Java Structure into C Structure. A java structure or a collection is interpreted as any java object on native side. Here is a small example of sending a java object (TextSegment.java) to C++ and printin it.
TextSegment.java
package com.text;
public class TextSegment {
public String text;
public int x;
public int y;
public TextSegment() {
}
public TextSegment(String text, int start, int end) {
this.text = text;
this.x = start;
this.y = end;
}
}
Main.java
package com.text;
public class Main {
public static void main(String[] args) throws InterruptedException {
System.loadLibrary("processEvents.dll");
System.out.println("Loading dll");
TextSegment ts = new TextSegment("testString",10,20);
Main.populateObject(ts);
}
private static native void populateObject(TextSegment ts);
}
Native method:
/*
* Class:com.test.Main
* Method:populateObject
* Signature: (Lcom//test/TextSegment;)V
*/
JNIEXPORT void JNICALL Java_com_test_Main_populateObject
(JNIEnv * env, jclass jcls, jobject obj){
//#define JNISTRING "Ljava/lang/String;"
jboolean bt = true;
jclasscls = env->GetObjectClass(obj);
jfieldID fidText = env->GetFieldID(cls, "text", "Ljava/lang/String;");
jstring txt = (jstring) env->GetObjectField(obj,fidText);
const char* tx = new char[256];
tx = env->GetStringUTFChars(txt, &bt);
jfieldID fidx = env->GetFieldID(cls, "x", "I");
int x = env->GetIntField(obj,fidx);
jfieldID fidy = env->GetFieldID(cls, "y", "I");
int y = env->GetIntField(obj,fidy);
printf("text=%s,x=%d, y=%d\n", tx,x, y);
}