Hi folks
I'm having some trouble returning a C struct to
Java using JNI. Currently I'm trying to use the javolution Struct library, though the documentation seems to be lacking. I have a small struct now, but will eventually have a
struct which contains pointers to other structs, char arrays, etc.
Here's what I have:
C Code:
typedef struct {
long count;
} Results;
JNIEXPORT jobject JNICALL Java_JTest_CTest (JNIEnv *env, jobject job) {
Results results;
results.count = 42;
printf("%li\n", results.count);
return (*env)->NewDirectByteBuffer(env, &results, sizeof(Results));
}
Java code:
class TestStruct extends Struct {
Signed32 count = new Signed32();
}
class JTest {
private native TestStruct CTest();
public static void main (
String args[]) {
JTest jt = new JTest();
TestStruct ts = jt.CTest();
System.out.println(ts.count);
}
static {
System.loadLibrary("CTest");
}
}
Can someone either point me in the right direction, tell me what I'm doing wrong, or maybe there is something completely different I should be doing?
TIA,
-ben