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 / February 2006

Tip: Looking for answers? Try searching our database.

JNI Invocation interface

Thread view: 
Tim - 16 Feb 2006 17:47 GMT
Having created a JVM from C++ using the Invocation interface, how can I
call back from the Java to my C++ code?  I am sure this must be simple
but I can't find a reference to how to do it, and I am up against the
clock

I am fine with using JNI to load & call a native DLL from Java, but
here I am wanting to call back to the invoking C++ code - ie I am not
using system.loadlibrary.

On a slightly  different tack, if I invoke the JVM frrm a DLL using the
invocation api, then use system.loadlibrary with that dll name, does
that just return a "handle" to the DLL that is already loaded (which
would enable me to accomplish the above) - or will it load a new
instance?

Thanks
Tim
Chris Uppal - 16 Feb 2006 18:27 GMT
> Having created a JVM from C++ using the Invocation interface, how can I
> call back from the Java to my C++ code?

There are only three ways to call from Java to C++ via JNI.

One is to use normal JNI code (as widely documented).  I doubt if that's what
you are looking for here.

Second is to use the RegisterNatives() function which will allow you to set (or
change if you wish) the function associated with any "native" method.

Last is to represent arbitrary C++ function pointers as int-s (or long-s) in
Java space.  Pass them around as much as you wish in Java, but when you want to
invoke the functions, you have to pass the int (or long) over JNI to your C++
code.  That code would cast the bit-pattern to a function pointer, and then
call it. Obviously handling arguments and return values will require a bit more
work.  You can get a similar effect (more type-safe but also more work for less
flexibility) by building an array of function pointers in C++ and passing
indexes into that array to Java instead of casting function pointers to ints.

   -- chris


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.