我现在一直在寻找一点点来弄清楚如何解决这个问题,但我发现没有什么能正确回答这个问题。我想我很接近了;我想要一个 jint* 和一个 int*,以及使用 (*env)->SetIntArrayRegion(...) 函数,
// This function will take an array of global integers that already exist in the
// c-side of the program, we'll call them 'data_ints[91]' (there are 91 just to clarify.)
/*...*/
int data_ints[] = {1,2,3,4,/*...*/90,91};
JNIEXPORT jintArray JNICALL Java_MarsRoverGUI_getData
(JNIEnv *, jobject, jint)
{
jintArray out_ints;
jint *outElements;
int i;
out_ints = (*env)->NewIntArray(env, 91);
outElements = (*env)->GetIntArrayElements(env,out_ints,0);
for (i = 0; i < 91; i++)
{
outElements[i] = data_ints[i];
}
(*env)->ReleaseIntArrayElements(env,out_ints,outElements,0);
// returns data_ints as a jintArray
return out_ints;
}
我离我有多近?我没有测试 JNI / 的有效方法:请随意提出方法!
吃饱了