Joemama
June 1st, 2002, 11:06 AM
Hey everyone! How do you convert a jchar to char and vice versa in C++? Thanks!
Joe
Joe
|
Click to See Complete Forum and Search --> : An Easy JNI/C++ Question Joemama June 1st, 2002, 11:06 AM Hey everyone! How do you convert a jchar to char and vice versa in C++? Thanks! Joe jVC++ June 3rd, 2002, 02:52 AM 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/ jVC++ June 3rd, 2002, 02:56 AM 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/tutorial/native1.1/implementing/cpp.html Joemama June 3rd, 2002, 02:08 PM Hey thanks a lot! codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |