JNI-如何将jshortArray转换为short * [英] JNI - How to convert jshortArray to short *
问题描述
我有一个 dll文件,其中包含 以下功能:
I have a dll file that contains the following function:
unsigned char * EncodingData(short Data[], int Length);
我想调用此本地方法 在Java中.所以我创造了一个 包装器dll ,其中包含与 以上功能
I want to call this native method in java. So I have created one wrapper dll that contains the follwing function corresponding to the above function
JNIEXPORT jcharArray JNICALL Java_com_common_FilterWrapper_EncodingData (JNIEnv * env, jclass cls, jshortArray shortData, jint len)
现在,我正在致电上述 JNI Java中的功能,并且 呼叫成功.
Now I am calling the above JNI function from java and it is being called successfully.
问题:
我想从包装器dll的功能中调用 dll文件的功能,但是我不知道如何转换以下内容:
I want to call the dll file's function from wrapper dll's function but I don't know how to convert the following:
-
jshortArray 到 short [] (将数据传递到期望 short [ ] ,而不是 jshortArray )
jshortArray to short [] (to pass the data to the dll file's function which is expecting short [] and not jshortArray)
unsigned char 到 jcharArray (将值返回给Java函数)
unsigned char to jcharArray (to return the value back to the java function)
注意:包装dll是用VC ++编写的
推荐答案
使用env-> GetShortArrayElements,例如,如果将jshortArray称为sdata_jshort,则short *指针称为short_data_c_pointer,然后
use env->GetShortArrayElements, for example if your jshortArray is called sdata_jshort, your short* pointer is called short_data_c_pointer, then
short_data_c_pointer = env-> GetFloatArrayElements(sdata_jshort,0);
short_data_c_pointer = env->GetFloatArrayElements(sdata_jshort, 0);
这篇关于JNI-如何将jshortArray转换为short *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!