Returning Arabic from JNI Call

I am 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 create a 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 expressions like

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 that the contents of ARABIC are inside a pointer to a cc pointer. Finally, in my java code, I have such a call

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

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

I just can't return some ARABIC character to my JAVA code. Is something wrong, what am I doing? I tried various alternatives such as

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

and return tempValue, but no luck. Its always trash on the java side.

+3
1

Java UTF-16, , 2 4 . , , MBCS (Multi-Byte Character Set) - 1-N .

JNI NewString , UTF-16, - - java . , , . , UTF-8, MultiByteToWideChar , java. , Windows - , , . iconv.

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);

, CP_UTF8 .

, UTF-8, cc[0] NewStringUTF . UTF-8 UTF-16.

+4

All Articles