dcsimg
how to return an int from native method.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rachna_Ringe
Posted On:   Saturday, May 19, 2001 04:06 AM

hi,
i want to return an int from my native method using JNI. I m developing an application for Mac OS.

I have a int value onw i want to return it to my java method.

please help, its urgent.

Thanx and Regds,
Rachna

Re: how to return an int from native method.

Posted By:   Alexander_Krapf  
Posted On:   Saturday, May 19, 2001 09:33 AM

Hi Rachna,


Returning an int from a native method is almost the same thing as returning nothing. What I mean is, that primitive return types are easy in JNI. You simply use the JNI primitive type that corresponds with your Java type.


In the case of a Java int, you have to use jint.


Your method might look like this:



JNIEXPORT jint JNICALL Java_myPackage_myClass_myMethod( JNIEnv * _env, jobject _this )
{
jint result = 5;

return result;
}


That's all. If you are interested in doing more exciting things with object references, you should look at our tool called JunC++ion. It allows you to implement native methods in C++, without having to worry about JNI at all. You can find out more about it at http://www.codemesh.com. We are currently not available on the Mac, but we're customer-driven, so if there are enough requests for it, we will port it.


Good luck,


Alex

About | Sitemap | Contact