Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:09:42+00:00 2026-05-20T18:09:42+00:00

I have been trying to return an ARABIC string from a JNI call. The

  • 0

I have been trying to return an ARABIC string from a JNI call.

The java method is as follows

private native String ataTrans_CheckWord(String lpszWord, String lpszDest, int m_flag, int lpszReserved);

lpszWord : Input English
lpszDest : Ignore
m_flag : Ignore
lpszReserved :Ignore

Now when I use javah to generate the header file I get a C++ header file with this signature

JNIEXPORT jstring JNICALL Java_MyClass_ataTrans_1CheckWord (JNIEnv* env, jobject, jstring, jstring, jint , jint)

Now in this C++ code I have statements such as this

JNIEXPORT jstring JNICALL Java_MyClass_ataTrans_1CheckWord(JNIEnv* env, jobject, jstring jstrInput,     jstring, jint , jint)
{    

char aa[10];
char* bb;
char** cc;
bb = aa;
cc = &bb;
jstring tempValue;

const char* strCIn = (env)->GetStringUTFChars(jstrInput , &blnIsCopy);

int retVal = pDllataTrans_CheckWord(strCIn, cc, m_flag, lpszReserved);

printf("Orginal Arabic Conversion Index 0: %s \n",cc[0]);   //This prints ARABIC properly 

tempValue = (env)->NewString((jchar* )cc[0],10); // convert char array to jstring

printf("JSTRING UNICODE Created : %s \n",tempValue); //This prints junk

return tempValue;

}

I believe the ARABIC content is inside the pointer to a pointer “cc”. Finally in my java code I have a call like this

String temp = myclassInstance.ataTrans_CheckWord("ABCDEFG", "",1, 0);

System.out.println("FROM JAVE OUTPUT : "+temp);  //Prints Junk

I just can’t get to return some ARABIC character out into my JAVA code. Is there something wrong I am doing? I have tried out various other alternates such as

tempValue = env->NewStringUTF("شسيشسيشسيشس");   

and return tempValue but no luck. Its always garbage on the JAVA side.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:09:42+00:00Added an answer on May 20, 2026 at 6:09 pm

    Java strings are internally UTF-16, an encoding which uses 2 or 4 bytes per character. Your translation system seems to return strings encoded in a MBCS (Multi-Byte Character Set) – 1-N bytes per character.

    The JNI NewString function expects data encoded as UTF-16, and you’re passing it something else – so in java you get garbage data. The one thing that is lacking from your information is which encoding your translation system uses. I’ll assume it’s UTF-8, and use MultiByteToWideChar to convert to the format java expects. The below code assumes that you’re doing this on Windows – if not, specify platform, and look at e.g. the iconv library.

    int Len = strlen(cc[0])*2+2;
    wchar_t * Buffer = (wchar_t *) malloc(Len);
    MultiByteToWideChar(CP_UTF8, 0, cc[0], -1, Buffer, Len);
    tempValue = (env)->NewString((jchar* )Buffer,wcslen(Buffer));
    free(Buffer);
    

    If you get strings as some other codepage, replace CP_UTF8 above.

    As a side note, if the encoding actually is UTF-8, you can simply pass your cc[0] to NewStringUTF instead – This function handles the UTF-8 to UTF-16 conversion internally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to understand how to return links from yql results, but
I have been trying to move away from using DECODE to pivot rows in
I have been trying, without success, to control an object within a class from
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have been trying to determine a best case solution for registering a COM
I have been trying to work my way through Project Euler, and have noticed
I have been trying to get around this error for a day now and
I have been trying to explain the difference between switch statements and pattern matching(F#)
I have been trying to read a picture saved in Access DB as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.