C++ JNI jobject conversion

Discussion in 'C++' started by Tim Wong, Dec 22, 2004.

  1. Tim  Wong

    Tim Wong Guest

    I have a java method setup where it will be accessed in C++ via JNI.
    The process is as follows:

    1) C++ function getObject(...) is called.

    2) getObject(...) uses JNI to access a java class method
    getJObject(...).

    3) getJObject(...) will do some calculations, save them to a complex
    object. This object is downcasted to the class "Object" and returned.

    4) C++ function getObject(...) get's back a <jbyteArray> from the JNI
    call and casts this to a jobject.

    My question is...what can methods can I perfrom on this jobject. What
    fields can I access? I'm trying to convert it into an already existing
    C++ class, but am unsure on what i can do.


    Help Please!

    Tim
     
    Tim Wong, Dec 22, 2004
    #1
    1. Advertising

  2. Tim Wong wrote:
    > I have a java method setup where it will be accessed in C++ via JNI.


    ....which is completely off-topic here...

    > The process is as follows:
    >
    > 1) C++ function getObject(...) is called.
    >
    > 2) getObject(...) uses JNI to access a java class method
    > getJObject(...).
    >
    > 3) getJObject(...) will do some calculations, save them to a complex
    > object. This object is downcasted to the class "Object" and returned.
    >
    > 4) C++ function getObject(...) get's back a <jbyteArray> from the JNI
    > call and casts this to a jobject.


    I can see everything relates to Java and the way _it_ is set to interact
    with C++, but C++ knows not how to interact with Java.

    > My question is...what can methods can I perfrom on this jobject.


    What can methods? What's a "can method"?

    > What
    > fields can I access?


    Fields? You mean, members? Public members from any non-member and
    non-friend functions, public and protected members from an object on
    the same class hierarchy and any members from a member or a friend.

    > I'm trying to convert it into an already existing
    > C++ class, but am unsure on what i can do.


    Do what you need, and if you encounter errors, post again. To the
    Java newsgroup. Unless your question is about C++ only, then your
    post should contain no mention of Java whatsoever.

    V
     
    Victor Bazarov, Dec 22, 2004
    #2
    1. Advertising

  3. You can decode your jbyteArray and create a java object from it, but there
    are no methods mystically attach to it,
    just by saving a stream of data... So.. you should be able to cast it to an
    array of bytes in java, and access methods of a java array, but that is
    about it there is not much else possible.

    What you want is to have a C++ wrapper that can be created from a JByteArray
    and something else, and a Java class that can be created from an array of
    bytes, and from something else... What you are doing by creating a
    jbytearray, is something like streaming an object. But you would need to
    create your own streaming operators/functions in both java an C++, so they
    would know what byte[X] of the byte stream is.

    Jesper

    "Tim Wong" <> wrote in message
    news:...
    > I have a java method setup where it will be accessed in C++ via JNI.
    > The process is as follows:
    >
    > 1) C++ function getObject(...) is called.
    >
    > 2) getObject(...) uses JNI to access a java class method
    > getJObject(...).
    >
    > 3) getJObject(...) will do some calculations, save them to a complex
    > object. This object is downcasted to the class "Object" and returned.
    >
    > 4) C++ function getObject(...) get's back a <jbyteArray> from the JNI
    > call and casts this to a jobject.
    >
    > My question is...what can methods can I perfrom on this jobject. What
    > fields can I access? I'm trying to convert it into an already existing
    > C++ class, but am unsure on what i can do.
    >
    >
    > Help Please!
    >
    > Tim
    >
     
    Jesper Madsen, Dec 22, 2004
    #3
  4. Jesper Madsen wrote:
    > "Tim Wong" <> wrote in message
    > news:...
    >
    >>I have a java method setup where it will be accessed in C++ via JNI.
    >>The process is as follows:
    >>
    >>1) C++ function getObject(...) is called.
    >>
    >>2) getObject(...) uses JNI to access a java class method
    >>getJObject(...).
    >>
    >>3) getJObject(...) will do some calculations, save them to a complex
    >>object. This object is downcasted to the class "Object" and returned.
    >>
    >>4) C++ function getObject(...) get's back a <jbyteArray> from the JNI
    >>call and casts this to a jobject.
    >>
    >>My question is...what can methods can I perfrom on this jobject. What
    >>fields can I access? I'm trying to convert it into an already existing
    >>C++ class, but am unsure on what i can do.


    Don't top-post. Rearranged.

    > You can [...]


    read the FAQ. And you should too.

    http://www.parashift.com/c -faq-lite/how-to-post.html


    Jonathan
     
    Jonathan Mcdougall, Dec 22, 2004
    #4
  5. Tim  Wong

    Tim Wong Guest

    Sorry,

    I figured I was in the right news group because it was a C++ coding
    question.


    Victor Bazarov wrote:
    > Tim Wong wrote:
    > > I have a java method setup where it will be accessed in C++ via

    JNI.
    >
    > ...which is completely off-topic here...
    >
    > > The process is as follows:
    > >
    > > 1) C++ function getObject(...) is called.
    > >
    > > 2) getObject(...) uses JNI to access a java class method
    > > getJObject(...).
    > >
    > > 3) getJObject(...) will do some calculations, save them to a

    complex
    > > object. This object is downcasted to the class "Object" and

    returned.
    > >
    > > 4) C++ function getObject(...) get's back a <jbyteArray> from the

    JNI
    > > call and casts this to a jobject.

    >
    > I can see everything relates to Java and the way _it_ is set to

    interact
    > with C++, but C++ knows not how to interact with Java.
    >
    > > My question is...what can methods can I perfrom on this jobject.

    >
    > What can methods? What's a "can method"?
    >
    > > What
    > > fields can I access?

    >
    > Fields? You mean, members? Public members from any non-member and
    > non-friend functions, public and protected members from an object on
    > the same class hierarchy and any members from a member or a friend.
    >
    > > I'm trying to convert it into an already existing
    > > C++ class, but am unsure on what i can do.

    >
    > Do what you need, and if you encounter errors, post again. To the
    > Java newsgroup. Unless your question is about C++ only, then your
    > post should contain no mention of Java whatsoever.
    >
    > V
     
    Tim Wong, Jan 4, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MP
    Replies:
    4
    Views:
    404
  2. Replies:
    10
    Views:
    7,067
  3. Vijayk
    Replies:
    12
    Views:
    7,950
    Chris Uppal
    Oct 25, 2005
  4. groupie

    jObject stays blank

    groupie, May 14, 2008, in forum: Java
    Replies:
    1
    Views:
    354
    Roedy Green
    May 15, 2008
  5. Philipp Kraus

    JNI generic type of jobject

    Philipp Kraus, Oct 4, 2011, in forum: Java
    Replies:
    6
    Views:
    911
    Daniel Pitts
    Oct 4, 2011
Loading...

Share This Page