Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

Calling a Java method from C++ via JNI problem.

Thread view: 
Sambucus - 28 Jun 2005 10:51 GMT
Hi all,
I am having some real difficulties calling a Java method from C++
code.

I load my c++ dll from java using:

static {
        System.loadLibrary("libname");
    }

I then init the dll by calling a method in the c++ dll like this:
(trying to save the references for env and obj)

static JNIEnv *jEnv;
static jobject jObj;

JNIEXPORT void JNICALL Java_poker_jni_JavaClassName_init(JNIEnv *env,
jobject obj){
        jEnv = env;
        jObj = env->NewGlobalRef(obj);
}

I have a function in my dll which I want to call a method (void
doTextOut(int i)) in my Java class that loaded the dll, it looks like
this:

void update(){

    jclass cls = jEnv->GetObjectClass(jObj);
    jmethodID mid = jEnv->GetMethodID(cls, "doTextOut", "(I)V");
    jEnv->CallVoidMethod(jObj, mid);

}

this method is called from my WndProc callback function.

When I do this the JVM will crash.

If I try to do exactly the same thing as update() in the JNIEXPORT
void JNICALL Java_poker_jni_JavaClassName_init(JNIEnv *env, jobject
obj) function it works!?! But the thing is that I really need to do it
from update()

Any suggestion on what I am doing wrong, or is this something that is
not even possible to do with JNI?

Any help would be greatly appreciated!

Best Regards
AET
Andrew Thompson - 28 Jun 2005 11:13 GMT
> When I do this the JVM will crash.

Does it give a stacktrace or log output?  If so..
what are a few specific lines of the error printout?

( Perhaps there is enough information in your original post
to get an answer from the JNI gurus, but exact the error
output can often help - and is sometimes vital. )

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Gordon Beaton - 28 Jun 2005 12:02 GMT
> I am having some real difficulties calling a Java method from C++
> code.

Please don't multipost. I've answered the question in another
newsgroup.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.