Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

JNI Question

Thread view: 
Edsoncv - 02 Mar 2007 16:05 GMT
Are there a way to attach to the env pointer a native object? Let me
be 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 function

setup (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 is
called from java, I don't know how to access native1 object from
"setup". Is it possible?

                                            Thanks
Gordon Beaton - 02 Mar 2007 17:17 GMT
> 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

Signature

[ 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

Edsoncv - 02 Mar 2007 18:49 GMT
> > 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
[quoted text clipped - 17 lines]
> [ 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.