eric07
asked on
JNI and return a boolean?
Can anyone show me a sample on how to return a boolean
here is my header.
JNIEXPORT jboolean JNICALL Java_JProfileIO_Open
(JNIEnv *, jobject, jint, jstring);
not quite sure on how to return a boolena.
Thanks
here is my header.
JNIEXPORT jboolean JNICALL Java_JProfileIO_Open
(JNIEnv *, jobject, jint, jstring);
not quite sure on how to return a boolena.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried the following but I get this error when I run the app:
I create a java package:
package jifwini;
public class JProfileIO
{
static
{
// Used to load the library
System.loadLibrary("jifwin i");
}
public JProfileIO(){}
public native boolean T();
}
then i compile it as following then
create a jar file
source for making the jar file:
cd c:\toolkit\jifwini\jar
del jifwini.jar
jar cf c:\toolkit\jifwini\jar\jif wini.jar -C c:\toolkit\jifwini\class jifwini\JProfileIO.class
then I create a javah file:
del c:\toolkit\jifwini\win32dl l\JProfile IO.h
javah -jni -d "c:\toolkit\jifwini\win32d ll" -classpath "c:\toolkit\jifwini\class\ jifwini" JProfileIO
then i create a dll.
I created a directory in my c:\temp\jio
where I place the dll.
My java app that uses the jni is as follows:
import jifwini.*;
class Test
{
public static Test obT;
String strValue;
public Test()
{
Test1();
}
public void Test1()
{
strValue = "Test this one";
System.out.println( strValue );
JProfileIO io = new JProfileIO();
if( io.T() == true )
System.out.println( "true" );
else
System.out.println( "false" );
}
public static void main(String[] args)
{
Test objT = new Test();
}
}
Then i compile and run it:
javac -classpath "c:\temp\jio\jifwini.jar;c :\temp\jio " *.java
java -classpath "c:\temp\jio\jifwini.jar;c :\temp\jio " Test
now it compiles fine but when it runs I get the following erro:
Exception in thread "main" java.lang.UnsatisfiedLinkE rror: T
at jifwini.JPRofileIO.T(Nativ e Method)
at Test.Test1(Test.java:19)
at Test.<init>(Test.java:10)
at Test.main(Test.java:31)
Here is what the dll does:
JNIEXPORT jboolean JNICALL Java_JProfileIO_T
(JNIEnv *env, jobject this)
{
return (JNI_TRUE);
}
I create a java package:
package jifwini;
public class JProfileIO
{
static
{
// Used to load the library
System.loadLibrary("jifwin
}
public JProfileIO(){}
public native boolean T();
}
then i compile it as following then
create a jar file
source for making the jar file:
cd c:\toolkit\jifwini\jar
del jifwini.jar
jar cf c:\toolkit\jifwini\jar\jif
then I create a javah file:
del c:\toolkit\jifwini\win32dl
javah -jni -d "c:\toolkit\jifwini\win32d
then i create a dll.
I created a directory in my c:\temp\jio
where I place the dll.
My java app that uses the jni is as follows:
import jifwini.*;
class Test
{
public static Test obT;
String strValue;
public Test()
{
Test1();
}
public void Test1()
{
strValue = "Test this one";
System.out.println( strValue );
JProfileIO io = new JProfileIO();
if( io.T() == true )
System.out.println( "true" );
else
System.out.println( "false" );
}
public static void main(String[] args)
{
Test objT = new Test();
}
}
Then i compile and run it:
javac -classpath "c:\temp\jio\jifwini.jar;c
java -classpath "c:\temp\jio\jifwini.jar;c
now it compiles fine but when it runs I get the following erro:
Exception in thread "main" java.lang.UnsatisfiedLinkE
at jifwini.JPRofileIO.T(Nativ
at Test.Test1(Test.java:19)
at Test.<init>(Test.java:10)
at Test.main(Test.java:31)
Here is what the dll does:
JNIEXPORT jboolean JNICALL Java_JProfileIO_T
(JNIEnv *env, jobject this)
{
return (JNI_TRUE);
}
eric07,
first your DLL is named jifwini.dll ?
System.loadLibrary is extending the given parameter to an operating system(OS) dependend shared library name.
Win: jfiwini.dll
Solaris: libjfwinwi.sl and so on.
Second the OS must be able to find the library.
Assuming you are using Win95/98 try to place the library in a directory where your PATH environment points to.
- for example:
do echo %PATH% at a command prompt and
you will get a list of directories where you can put it.
third there is another load call you can use:
System.load("c:\\temp\\jio \\fiwini.d ll");
I never tried this because this will only run at one platform.
Happy eastern
jf
first your DLL is named jifwini.dll ?
System.loadLibrary is extending the given parameter to an operating system(OS) dependend shared library name.
Win: jfiwini.dll
Solaris: libjfwinwi.sl and so on.
Second the OS must be able to find the library.
Assuming you are using Win95/98 try to place the library in a directory where your PATH environment points to.
- for example:
do echo %PATH% at a command prompt and
you will get a list of directories where you can put it.
third there is another load call you can use:
System.load("c:\\temp\\jio
I never tried this because this will only run at one platform.
Happy eastern
jf
ASKER