Hallo,
habe ein kleines HalloWelt Beispiel mit Java und C++ gemacht, sprich Java ruft ein C++ “Programm” auf und das gibt dann Hallo Welt aus. Jetzt würde ich das ganze sehr gerne so verändern das dass C++ “Programm” dem Java Programm einen Wert (Zahl) zurückgibt, kann mir da vielleicht jemand helfen?
So sieht das ganze bis jetzt aus, aber was muß ich in die beiden Klassen noch alles einbauen das Java was zurückbekommt:
public class HalloWeltBeispiel {
public static void main(String[] args){
HalloWelt obj = new HalloWelt();
obj.printHallo();
}
}
class HalloWelt {
static {
System.loadLibrary("HalloWelt");
}
public native void printHallo();
}
//HalloWelt.cpp
#include <jni.h>
#include "HalloWelt.h"
#include <iostream>
#include <stdio.h>
using namespace std;
JNIEXPORT void JNICALL Java_HalloWelt_printHallo(
JNIEnv *env, jobject myClass){
printf("Hallo Welt, sagt das C Programm !!!!!
");
int wert1 = 10;
cout << "wert1: " <<wert1 << '
';
}