I'm using a basic_string<wchar_t>
type and need to convert it into a jstring to pass through a JNI layer. I'm wondering what the best way to do that is. I have a function that can give me a std::string
from my basic_string<wchar_t>
type, so an answer to that would also be cool.
Cheers.
You'll need to convert the std::basic_string into UTF-8. Look into what your wstring -> string conversion does.
Sun has a JNI tutorial that shows how to convert a char* into a jstring (using some UTF conversion routines). You could use your wstring->string, then pass in string.c_str() to the NewStringUTF function:
Untested Code:
JNIEXPORT jstring JNICALL StringTest(JNIEnv *env) {
const char* test = "something";
return env->NewStringUTF(test);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With