From c0544ee6f1f074db2163484633582794367c2877 Mon Sep 17 00:00:00 2001 From: zeekling Date: Sun, 31 Dec 2023 17:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djni=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E4=B9=B1=E7=A0=81=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/native/jniTestNative.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/native/jniTestNative.c b/src/main/native/jniTestNative.c index 12368dc..b09c371 100644 --- a/src/main/native/jniTestNative.c +++ b/src/main/native/jniTestNative.c @@ -11,15 +11,17 @@ extern "C" { JNIEXPORT void JNICALL Java_com_zeekling_cn_jni_JniTest_say(JNIEnv* env, jclass cls, jstring j_str) { const char *c_str = NULL; 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) { printf("out of memory.\n"); return NULL; } - (*env)->ReleaseStringUTFChars(env, j_str, c_str); + printf("Hello,I'm C++,the Java Str is:%s\n", c_str); sprintf(buff, "hello %s", c_str); + (*env)->ReleaseStringUTFChars(env, j_str, c_str); return (*env)->NewStringUTF(env, buff); } #ifdef __cplusplus -- 2.45.2