Article View: borland.public.cppbuilder.nativeapi
Article #8903JNI-Java Native interface
From: Simon Rydberg
Date: Mon, 30 Aug 2004 17:15
Date: Mon, 30 Aug 2004 17:15
47 lines
2306 bytes
2306 bytes
Hi!
I need to connect a java application and a bcb application. So far I
have understood that what I need to use is the jni.
Trying some examples on the net I have one big problem, I can't get my
bcb-app to read or execute non-static variables or methods in a java class.
this is the code that is not working.
JNIEXPORT void JNICALL Java_mini_1klass_ladda_1dll
(JNIEnv *env, jobject obj, jstring s)
{
jclass c = env->GetObjectClass(obj);
jfieldID fid = env->GetStaticFieldID(c, "inta", "I");
// gets a value that is not the correct value. possible read of
// the wrong adress??
jfieldID fid2 = env->GetFieldID(c, "intb", "I");
jint si = env->GetStaticIntField(c, fid);
jint si2 = env->GetIntField(c, fid2);
int inta = si;
printf("CPP DEBUG: inta = %d\n", inta);
int intb = si2;
printf("CPP DEBUG: intb = %d\n", intb);
env->SetStaticIntField(c, fid, 12);
// set the int to a new value, but it does not show up inside the java
env->SetIntField(c, fid2, 55);
}
I assume that it's wrong to send in the jclass object and that I should
use the jobject instead, the problem is that I can't find the method
that I should use then. Simply casting the jobject to a jclass donοΏ½t
work, even though the documentation says it's the same type of object...
I'm using java 1.4.2 and bcb 6.
Greetings
Simon
Technical Details
Message-ID:
<41336087@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,423ba63725b8443f,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII Date: Mon, 30 Aug 2004 19:15:11 +0200 From: Simon Rydberg <simpor81@hotmail.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803 X-Accept-Language: sv, en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: JNI-Java Native interface Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 83.226.21.131 Message-ID: <41336087@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1093886087 83.226.21.131 (30 Aug 2004 10:14:47 -0700) Lines: 47 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail