Wednesday, 21 August 2013

How to make C++ work interactively with Java GUI using JNI?

How to make C++ work interactively with Java GUI using JNI?

Ok..
I am creating a simple Win32 console application that loads Java GUI which
has it's form file..
However, I got some problem.. Here is a part of code..
if(status != JNI_ERR)
{
cls = env->FindClass("PWNJava");
if(cls != 0)
{
cout<<"class found!"<<endl;
mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
env->CallStaticVoidMethod(cls, mid);
}
else
{
printf("Can't find class\n");
return;
}
jvm->DestroyJavaVM();
cout<<"\nJVM Destroyed!!"<<endl;
}
Ok.. My problem is that, When Java GUI application starts, the console
application get stopped.
If I debug it each line, Java Gui Application starts at a code line
"jvm->DestroyJavaVM();", which is presumed to kill Java Virtual Machine
but not create Java GUI application. it just automatically terminates
console application if I close my Java GUI application.
about a code at a bottom, cout<<"\nJVM Destroyed!!"<
this "JVM Destroyed!!" never shows on Console Windows... Once after I
closed Java GUI Application, Console application does not work anymore. it
just shows "push any button to close".
What I want to do later is, After I choose any radio button and lastly
click finish button on Java GUI, then Java GUI application should be
terminated, and then c++ program should be able to receive variables from
Java GUI Program. idk it is possible or impossible though..?
But First of all, this console application seem to be automatically
terminated by Java GUI Program.
How to fix this automatic termination of Console Program by Java Gui
Application?
Below is address of downloadable source code: (MSVS 2008 for C++ and
Netbeans for Java)
http://cfile209.uf.daum.net/attach/241D3F3D5214C4ED07ECE1

No comments:

Post a Comment