I am using JNI to pass data between C++ and Java. I need to pass a 'long' type, and am doing so using something like:
long myLongVal = 100;
jlong val = (jlong)myLongVal;
CallStaticVoidMethod(myClass, "(J)V", (jvalue*)val);
However in Java, when the 'long' parameter is retrieved, it gets retrieved as some very large negative number. What am I doing wrong?
CallStaticVoidMethod(myClass, "(J)V", (jvalue*)val);
This is undefined behaviour. You are casting an integer to be a pointer. It is not a pointer. You need, at the very least, to pass the address. This code would on most platforms instantly crash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With