By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Java from C++

P: n/a
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.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

ToSam wrote:
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

Jul 23 '05 #2

P: n/a
ToSam wrote:
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.

--
- gipsy boy
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.