parent
1e634c22d2
commit
205978c59f
@ -11,15 +11,17 @@ extern "C" {
|
|||||||
JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniTest_say(JNIEnv* env, jclass cls, jstring j_str) {
|
JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniTest_say(JNIEnv* env, jclass cls, jstring j_str) {
|
||||||
const char *c_str = NULL;
|
const char *c_str = NULL;
|
||||||
char buff[128] = { 0 };
|
char buff[128] = { 0 };
|
||||||
c_str = (*env)->GetStringUTFChars(env, j_str, NULL);
|
jboolean isCopy;
|
||||||
|
c_str = (*env)->GetStringUTFChars(env, j_str, &isCopy);
|
||||||
if (c_str == NULL)
|
if (c_str == NULL)
|
||||||
{
|
{
|
||||||
printf("out of memory.\n");
|
printf("out of memory.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
(*env)->ReleaseStringUTFChars(env, j_str, c_str);
|
|
||||||
printf("Hello,I'm C++,the Java Str is:%s\n", c_str);
|
printf("Hello,I'm C++,the Java Str is:%s\n", c_str);
|
||||||
sprintf(buff, "hello %s", c_str);
|
sprintf(buff, "hello %s", c_str);
|
||||||
|
(*env)->ReleaseStringUTFChars(env, j_str, c_str);
|
||||||
return (*env)->NewStringUTF(env, buff);
|
return (*env)->NewStringUTF(env, buff);
|
||||||
}
|
}
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user