JNI Question

  • Follow


Are there a way to attach to the env pointer a native object? Let mebe more clear.I have the following native function (simplified):solve(JNIEnv * env , jobject obj1 , void* alpha){....nativeobject *native1 = new nativeobject;}and I wan to acces the j1 object form another native functionsetup (JNIEnv * env){....}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 iscalled from java, I don't know how to access native1 object from"setup". Is it possible?                                             Thanks
0
Reply edsoncv (22) 3/2/2007 4:05:22 PM

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 toboth methods (i.e. not as a local variable in solve() like yourexample).Or, remembering that even native methods have return values, return itto the caller (cast to jlong) so that it can be passed back to thenext method, where you cast it back to the appropriate pointer typebefore 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 
0
Reply Gordon 3/2/2007 5:17:25 PM


On Mar 2, 2:17 pm, Gordon Beaton <n...@for.email> 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 eThanks Gordon, I think I'll pick the second option.
0
Reply Edsoncv 3/2/2007 6:49:27 PM

2 Replies
88 Views

(page loaded in 0.058 seconds)

Similiar Articles:













7/7/2012 4:20:57 AM


Reply: