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. Advertisements

  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. Advertisements

  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. Advertisements

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. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    1,108
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    1,199
    Pasturel Jean-Louis
    Mar 3, 2004
  3. MP
    Replies:
    4
    Views:
    523
  4. vasanth
    Replies:
    0
    Views:
    3,260
    vasanth
    Jan 25, 2005
  5. Replies:
    10
    Views:
    7,589
  6. Vijayk
    Replies:
    12
    Views:
    8,843
    Chris Uppal
    Oct 25, 2005
  7. groupie

    jObject stays blank

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

    JNI generic type of jobject

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