Java from C++

T

ToSam

I try to be more specific now: In VC++ I define a OnButtonClick
method. Once the button is clicked, a piece of JAVA-code in a file
must be loaded and compiled using a Java-Compiler (javac). The Java
program returns an integer, say. A Java-example may be this:

public class Main {

public Main() {
}

public static void main(String[] args) {

try{

MCDVersion pMCDVersion = new MCDVersion();
int major = pMCDVersion.getMajor();

} catch (com.inzoom.comjni.ComJniException e){
System.err.println("Exception: "+e.getMessage());
}
}
}

The desired result is in major. After having compiled this code from
C++, it must be executed in order to get the value of major. Then I
would like to pass this integer (that was generated from the Java
code) back to C++, and C++ uses it further. Here is my OnButtonClick
method:

void CTestDlg::OnButtonClick()
{
...
// compile Main.java
system("javac C:\\TEST\\Main.java");
// run Main.class
system("java C:\\TEST\\Main");
...
}

Questions are this: Is this the best way to do it? Secondly, how do
I pass the integer result to C++ so that it can be used again?

Thanks again.
 
S

Shan

ToSam said:
I try to be more specific now: In VC++ I define a OnButtonClick
method. Once the button is clicked, a piece of JAVA-code in a file
must be loaded and compiled using a Java-Compiler (javac). The Java
program returns an integer, say. A Java-example may be this:

public class Main {

public Main() {
}

public static void main(String[] args) {

try{

MCDVersion pMCDVersion = new MCDVersion();
int major = pMCDVersion.getMajor();

} catch (com.inzoom.comjni.ComJniException e){
System.err.println("Exception: "+e.getMessage());
}
}
}

The desired result is in major. After having compiled this code from
C++, it must be executed in order to get the value of major. Then I
would like to pass this integer (that was generated from the Java
code) back to C++, and C++ uses it further. Here is my OnButtonClick
method:

void CTestDlg::OnButtonClick()
{
...
// compile Main.java
system("javac C:\\TEST\\Main.java");
// run Main.class
system("java C:\\TEST\\Main");
...
}

Questions are this: Is this the best way to do it? Secondly, how do
I pass the integer result to C++ so that it can be used again?

Thanks again.

In c++ standard there is no way you can invoke some other compiler to
run and get the results from the different language. Your solution of
using system() is not standard C++. It is operating system specific
call. Please go to the appropriate newsgroup to solve your problem.
Regards
Shan
 
G

gipsy boy

ToSam said:
I try to be more specific now: In VC++ I define a OnButtonClick
method. Once the button is clicked, a piece of JAVA-code in a file
must be loaded and compiled using a Java-Compiler (javac). The Java
program returns an integer, say. A Java-example may be this:

public class Main {

public Main() {
}

public static void main(String[] args) {

try{

MCDVersion pMCDVersion = new MCDVersion();
int major = pMCDVersion.getMajor();

} catch (com.inzoom.comjni.ComJniException e){
System.err.println("Exception: "+e.getMessage());
}
}
}

The desired result is in major. After having compiled this code from
C++, it must be executed in order to get the value of major. Then I
would like to pass this integer (that was generated from the Java
code) back to C++, and C++ uses it further. Here is my OnButtonClick
method:

void CTestDlg::OnButtonClick()
{
...
// compile Main.java
system("javac C:\\TEST\\Main.java");
// run Main.class
system("java C:\\TEST\\Main");
...
}

Questions are this: Is this the best way to do it? Secondly, how do
I pass the integer result to C++ so that it can be used again?

off topic, but..as you might have guessed, this is not the way to do it.
You probably need JINI.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top