CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Posts
    5

    Exclamation An Easy JNI/C++ Question

    Hey everyone! How do you convert a jchar to char and vice versa in C++? Thanks!
    Joe

  2. #2
    Join Date
    Dec 2000
    Posts
    13
    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/

  3. #3
    Join Date
    Dec 2000
    Posts
    13
    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

  4. #4
    Join Date
    May 2002
    Posts
    5
    Hey thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured