|
-
June 1st, 2002, 11:06 AM
#1
An Easy JNI/C++ Question
Hey everyone! How do you convert a jchar to char and vice versa in C++? Thanks!
Joe
-
June 3rd, 2002, 02:52 AM
#2
Do you mean that you want to get or set the fields passed from your Java Env.... in C/C++ ... If that is so .... you may try this ..
Suppose you have int variable named 'myChar' in Java.....
//C Notation...
JNIEXPORT jstring JNICALL Java_RWPrnSettings_ReadPrnSettings
(JNIEnv *env, jobject obj)
{
....
jchar ch;
jClass cls;
jfieldID fid;
cls = (*env)->GetObjectClass(env,obj);
fid = (*env)->GetFieldID(env,cls,"myChar","C");
....
ch = (*env)->GetCharField(env,obj,fid); //To get Val.
.......
ch = 'a';
(*env)->SetCharField(env,obj,fid,ch); //To set Val.
...
}
For More info...
Refer to jni.h file packaged with your JDK and also an article
at SUN : http://java.sun.com/docs/books/tutorial/native1.1/
-
June 3rd, 2002, 02:56 AM
#3
BTW the method signature above is returning jstring... , if you have any others change it or others make it... 'void'...
For C++ , there will be a small change in calling the functions...
Checkout this URL for the minor changes....
http://java.sun.com/docs/books/tutor...nting/cpp.html
-
June 3rd, 2002, 02:08 PM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|