This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: 2 questions...
- To: simon@unique-id.com
- Subject: Re: 2 questions...
- From: Andrew Haley <aph@pasanda.cygnus.co.uk>
- Date: 3 Jun 1999 12:14:31 -0000
- CC: java-discuss@sourceware.cygnus.com
> Date: Thu, 03 Jun 1999 12:58:19 +0100
> From: simon@unique-id.com
>
> 2)
> Is it possible to link with other object files, say I wanted to link
> with
> libTIFF.a (or .so). Presumably there are calling conventions for
> accessing other native code ?
Have a look at libgcj: there are many examples of library calls. The
general rule is that you my only make calls from Java code to C++, not
C. As a consequence of this, you will have to write some C++ wrapper
functions.
> My understanding of JNI is that I need to do special things in my
> native code in order to have them called by Java. The CNI interface
> seems similar.
>
> I guess what I'm asking is... is it possible to (for example) convert
> from the java.lang.String class to a char* transparently ?
"transparently"? Have a look at java::io::File::stat in natFile.cc.
It begins:
jboolean
java::io::File::stat (jstring canon, jint query)
{
if (! canon)
return false;
char buf[MAXPATHLEN];
jsize total = JvGetStringUTFRegion (canon, 0, canon->length(), buf);
buf[total] = '\0';
That's what you have to do. It's not appropriate simply to convert
calls to libraries directly to static Java methods, because usually
you have to do argument checking and throw exceptions when things go
wrong, rather than just failing.
Andrew.