JNI Question  
Author Message
Edsoncv





PostPosted: 2007-3-3 2:49:00 Top

java-programmer, JNI Question On Mar 2, 2:17 pm, Gordon Beaton <email***@***.com> wrote:
> On 2 Mar 2007 08:05:22 -0800, Edsoncv wrote:
>
> > If I have only the C part, I would cast the "native1" object, pass
> > to "setup" and cast back the object, but since the setup function is
> > called from java, I don't know how to access native1 object from
> > "setup". Is it possible?
>
> Of course.
>
> Either store it someplace in the native code where it's visible to
> both methods (i.e. not as a local variable in solve() like your
> example).
>
> Or, remembering that even native methods have return values, return it
> to the caller (cast to jlong) so that it can be passed back to the
> next method, where you cast it back to the appropriate pointer type
> before attempting to use it.
>
> /gordon
>
> --
> [ don't email me support questions or followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e

Thanks Gordon, I think I'll pick the second option.

 
Edsoncv





PostPosted: 2007-3-3 2:49:00 Top

java-programmer >> JNI Question On Mar 2, 2:17 pm, Gordon Beaton <email***@***.com> wrote:
> On 2 Mar 2007 08:05:22 -0800, Edsoncv wrote:
>
> > If I have only the C part, I would cast the "native1" object, pass
> > to "setup" and cast back the object, but since the setup function is
> > called from java, I don't know how to access native1 object from
> > "setup". Is it possible?
>
> Of course.
>
> Either store it someplace in the native code where it's visible to
> both methods (i.e. not as a local variable in solve() like your
> example).
>
> Or, remembering that even native methods have return values, return it
> to the caller (cast to jlong) so that it can be passed back to the
> next method, where you cast it back to the appropriate pointer type
> before attempting to use it.
>
> /gordon
>
> --
> [ don't email me support questions or followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e

Thanks Gordon, I think I'll pick the second option.