I'm actually a Java programmer, and I'm messing with JNI a bit,
so I've managed to pass an int from java to c++ and to c# and back.
no problems cause it gets serialized automatically.
but when dealing with string - the object JNI passes is jstring which
casts to char* but how to pass it to c#?
Do I need to Marshal it on the c# side??? can someone post a bit of
code example????
my C++ code is like so :
The ExecuteStringC class :
and finally the C# part :
Since I'm executing this code from Java it fails but I can't tell where, is it in the first or 2nd classes (C++) ??? or maybe in the C# side.
I do believe it's the lather, but if anyone can shed some info on the subject (posting some code will be nice...)
10x in advance to all contributors :)
so I've managed to pass an int from java to c++ and to c# and back.
no problems cause it gets serialized automatically.
but when dealing with string - the object JNI passes is jstring which
casts to char* but how to pass it to c#?
Do I need to Marshal it on the c# side??? can someone post a bit of
code example????
my C++ code is like so :
Code:
...
JNIEXPORT jint JNICALL Java_jni_ExecuteString_executeString (JNIEnv *env, jobject, jstring strinput) {
ExecuteStringC* myObj = new ExecuteStringC();
const char *str;
int result;
str = env->GetStringUTFChars(strinput, 0);
result = myObj->callExecuteString(str);
env->ReleaseStringUTFChars(strinput, str);
return result;
Code:
public __gc class ExecuteStringC
{
public:
CSharpExecuteString __gc *execObj;
ExecuteStringC() {
execObj = new CSharpExecuteString();
}
int callExecuteString(const char* str) {
return execObj->executeString(str);
}
};
Code:
class CSharpExecuteString
{
public int executeString(string stringToExec)
{
Console.WriteLine("C# Says : " + stringToExec);
return 0;
}
}
I do believe it's the lather, but if anyone can shed some info on the subject (posting some code will be nice...)
10x in advance to all contributors :)
Comment