JNI converting jstring to char *

后端 未结 2 1736
逝去的感伤
逝去的感伤 2020-11-27 11:03

I have passed a URL string from Java to C code as jstring data type through the use of JNI. And my library method needs a char * as url.

Ho

2条回答
  •  情深已故
    2020-11-27 11:40

    Here's a a couple of useful link that I found when I started with JNI

    http://en.wikipedia.org/wiki/Java_Native_Interface
    http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html

    concerning your problem you can use this

    JNIEXPORT void JNICALL Java_ClassName_MethodName(JNIEnv *env, jobject obj, jstring javaString)   
    {
       const char *nativeString = env->GetStringUTFChars(javaString, 0);
    
       // use your string
    
       env->ReleaseStringUTFChars(javaString, nativeString);
    }
    

提交回复
热议问题