aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JNI problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JNI problem" Watch "JNI problem" New topic
Author

JNI problem

amit shukla
Ranch Hand

Joined: Oct 25, 2000
Posts: 45
Hi all,
I guess we dont have any forum particularly for JNI... thats y posting the porblem here...
whats the difference between passing a jstring from a java program to 'c' method AND using scanf from within the 'c' code to read the string from java execution environment... somewhat like done in the following 'c' method.....
here jstring 'str' is passed from a java method AND another string is read from the command prompt using scanf("%s", buf)
why in the first case we require conversion from unicode to UTF8 and not in the second case ....

JNIEXPORT jstring JNICALL Java_HelloName_displayHelloName(JNIEnv *env, jobject obj, jstring str)
{
char buf[128];
const char *s = (*env)->GetStringUTFChars(env, str, 0);
printf("Hello , %s\n",s);
(*env)->ReleaseStringUTFChars(env, str, s);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);

}

gat98
Greenhorn

Joined: Jul 06, 2001
Posts: 3
Originally posted by amit shukla:
Hi all,
I guess we dont have any forum particularly for JNI... thats y posting the porblem here...
whats the difference between passing a jstring from a java program to 'c' method AND using scanf from within the 'c' code to read the string from java execution environment... somewhat like done in the following 'c' method.....
here jstring 'str' is passed from a java method AND another string is read from the command prompt using scanf("%s", buf)
why in the first case we require conversion from unicode to UTF8 and not in the second case ....

JNIEXPORT jstring JNICALL Java_HelloName_displayHelloName(JNIEnv *env, jobject obj, jstring str)
{
char buf[128];
const char *s = (*env)->GetStringUTFChars(env, str, 0);
printf("Hello , %s\n",s);
(*env)->ReleaseStringUTFChars(env, str, s);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);

}


Hey
If you know the answer please let me know
thanks
gat
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1449
gat98,
Please review the JavaRanch naming policy and re-register.
Thanks,
John


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
 
wood burning stoves
 
subject: JNI problem