dcsimg
Pass/Return JString in C++
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, August 27, 2001 04:14 PM

Using JNI, how do I pass a String to the C++DLL, and have it return a "string" back. Before it returns the "string", it has to call a C++ function, to get the "string". Below is my C++ code: #include #include "PassReturnString.h" char returnString(const char *); JNIEXPORT jstring JNICALL Java_PassReturnString_showString (JNIEnv *env, jobject obj, jstring jstr) { const char* str = env->GetStringUTFChars(jstr, 0); const char* ret[] = (char*)returnString(str); env->ReleaseStringUTFChars(jstr, str); return env->NewStringUTF(ret); } ch   More>>

Using JNI, how do I pass a String to the C++DLL, and have it return a "string" back. Before it returns the "string", it has to call a C++ function, to get the "string". Below is my C++ code:



#include


#include "PassReturnString.h"



char returnString(const char *);



JNIEXPORT jstring JNICALL Java_PassReturnString_showString
(JNIEnv *env, jobject obj, jstring jstr) {


const char* str = env->GetStringUTFChars(jstr, 0);

const char* ret[] = (char*)returnString(str);

env->ReleaseStringUTFChars(jstr, str);

return env->NewStringUTF(ret);

}



char returnString(const char *c) {

char *back;

if(c == "1") {

back = ("%s", "Hello");

return *back;

}

else if(c == "2") {

back = ("%s", "World");

return *back;

}

else if(c == "3") {

back = ("%s", "!");

return *back;

}

else {

back = ("%s", "Bad");

return *back;

}

}

   <<Less
About | Sitemap | Contact