468,765 Members | 1,181 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Java from C++

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
2 1513

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
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.

Similar topics

reply views Thread by Ravi Tallury | last post: by
1 post views Thread by ptaz | last post: by
12 posts views Thread by Mark Fink | last post: by
1 post views Thread by jaimemartin | last post: by
oll3i
reply views Thread by oll3i | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.