Convert managed unsigned char* into a jbyte*

How can I convert a managed unsigned char* into a jbyte*? since I'm new to this, a snippet would be helpful too.

here is my native code:-

JNIEXPORT jobject JNICALL Java_com_me_NativeCaller_processImages
    (JNIEnv *env, jclass c, jbyteArray front, jbyteArray back){
unsigned char* frontBuffer = convertJByteArrayIntoUnsignedChar(env, front);
unsigned char* backBuffer = convertJByteArrayIntoUnsignedChar(env, back);
System::Collections::Generic::List<cli::array<unsigned char>^>^ returnedValue = processImages(frontBuffer,backBuffer);
jbyte* bytes;
bytes = returnedValue[1];
bytes = returnedValue[2];
jbyteArray intermediateArray1 = env->NewByteArray(1);

return static_cast<jobject>(intermediateArray1);


here at bytes = returnedValue[1];I'm getting an error saying "a value of type cli::array^ cannot be assign to an entity of type jbyte*"

c# code which returns a List of byte[] :-

public static List<byte[]> processImages(byte[] frontImage, byte[] backImage)

        List<Image> imagesToReturn = GetAllPages(tiffFileBuffer);//convert byte[] into two separate images
        front = imagesToReturn[0];
        back = imagesToReturn[1];

        List<byte[]> bytesToReturn = new List<byte[]>();

        return bytesToReturn;

it's really helpful if someone can help me with this.


To convert a data in unsigned char * format to a jbyteArray which is byte[] in Java, if I remember rightly you want to do something like:

JNIEnv *env... //usually from your method signature in the jni
unsigned char *myCharData; // by stipulation you have this somehow.
const int yourArraySize = // as per usual number of elements in the char *
jbyteArray myJByteArray = env->NewByteArray(yourArraySize);
env->SetByteArrayREgion(myJByteArray, 0, yourArraySize, (jbyte *) myCharData);

// your myJByteArray is ready to use. Don't forget to memory manage your myCharData, mind!

The c-style cast works given the type definition of the jbyte, which we can assume is safe in this implementation.

At the time of writing this question, I haven't been aware where the data was coming from, so taking a guess, Android-specific docs, can be found here.

Need Your Help

Error notification not working

javascript jquery ajax error-handling

My problem happens to be the error, I am attempting to produce an error, in this case the error being hiding the loading symbol and showing a refresh button in order for the user to reload the page...

PG::UndefinedColumn: ERROR: column "image_file_name" of relation "articles" does not exist

ruby-on-rails postgresql heroku database-migration heroku-postgres

Can someone please help me with runing heroku run db:migrate? I've forgot to run db:migration on heroku along with migration on dev env. I made coulple of them and now I'm receiving the below error: