gpt4 book ai didi

java - JNI - 如何将 jshortArray 转换为短 *

转载 作者:行者123 更新时间:2023-12-01 06:21:01 25 4
gpt4 key购买 nike

I have a dll file that contains the following function:

unsigned char * EncodingData(short Data[], int Length);

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)

Now I am calling the above JNI function from java and it is being called successfully.

问题:

我想从包装器dll的函数调用dll文件的函数,但我不知道如何转换以下内容:

  • jshortArrayshort [](将数据传递给 dll 文件的函数,该函数需要 short [ ] 而不是 jshortArray)

  • unsigned charjcharArray(将值返回给 java 函数)

注意:包装器dll是用VC++编写的

最佳答案

unsigned short tempElem;
jshort* test = env->GetShortArrayElements(shortData, NULL);
int size = (sizeof(test) / sizeof(*test)) - 1;
for (int i = 0; i < size; i++) {
tempElem = (unsigned short)test[i]);
printf("[%d] test %u || size = %d\n", i, tempElem, size);
}

关于java - JNI - 如何将 jshortArray 转换为短 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5586155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com