JNI constructor for java objects

M

M. Fernandez

Hello,

I would like to know if it is possible to create java objects from c++
and sending them back to the Java main application, something like:

JNIEXPORT myJavaObj JNICALL Java_template_getObj
(JNIEnv *env, jobject obj)
{
jclass myClass;

//Somehow, create here the java object..
myClass = (*env)->FindClass(env, "()LMyJavaClass;");

//Create the object somehow...

//Return the object.
return myObj;
}

thanks a lot,

Marcelo
 
G

Gordon Beaton

I would like to know if it is possible to create java objects from c++
and sending them back to the Java main application

Of course it is. Many of your JNI questions seem to indicate that you
can't be bothered to read any documentation before posting. Here are
two useful links, please follow them:

http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html
http://java.sun.com/docs/books/jni/html/jniTOC.html

Use FindClass. Find the appropriate constructor, i.e. a non-static
method named "<init>". Invoke NewObject.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top