How to convert jbyteArray to native char* in jni

How to convert jbyteArray to native char* in jni - Hello friend inabnomaniiyaha, In the article that you read this time with the title How to convert jbyteArray to native char* in jni, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : How to convert jbyteArray to native char* in jni
link : How to convert jbyteArray to native char* in jni

Baca juga


How to convert jbyteArray to native char* in jni

I am trying to convert a jbyteArray to native c string (char*) in jni? Unfortunately I can't find any documentation on how to do that. I'm invoking a java function with the following prototype in the c code.

public static byte[] processFile(byte[] p_fileContent)

In the c code I am invoking this function which is returning a byte array. The content of this byte array is a java string. But I need to convert it to a c string.

jbyteArray arr = (jbyteArray) env->CallObjectMethod(clsH, midMain, jb);

printf("%s\n", (char*) arr);

I believe you would use GetByteArrayElements and ReleaseByteArrayElements. Something like:

boolean isCopy;

jbyte* b = GetByteArrayElements(env, arr, &isCopy);

You should be able to cast b to char* at this point in order to access the data in the array. Note that this may create a copy of the data, so you'll want to make sure to release the memory using ReleaseByteArrayElements:

ReleaseByteArrayElements(env, arr, b, 0);

The last parameter is a mode indicating how changes to b should be handled. 0 indicates that the values are copied back to arr. If you don't want to copy the data back to arr, use JNI_ABORT instead.



That's the articleHow to convert jbyteArray to native char* in jni

That's it for the article How to convert jbyteArray to native char* in jni this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleHow to convert jbyteArray to native char* in jni with link addresshttps://inabnonapudyawanabing.blogspot.com/2021/04/how-to-convert-jbytearray-to-native.html

0 Response to "How to convert jbyteArray to native char* in jni"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...