0

i'm quite new at jni so please excuse my code if its messy. So i made a function in java called getPid() to get the pid of a running process. And whenever it finds the pid, it sets the value of this variable: public int pid to the pid value. I wanna get this variable's value in c++, and this is what i have right now:

int getPid(JNIEnv* _env, jobject _object) {
    jclass myClass = _env->FindClass("com/dark/force/MenuService");
    jfieldID jfieldId = _env->GetFieldID(myClass, "pid", "I");
    jint i =_env->GetIntField(_object, jfieldId);
    return i;
}

And i wanna invoke this in the same c++ file. How can i do that? Any help is appreciated!

Arc
  • 3
  • 3
  • You'd have to get a `JNIEnv*` for the current thread (see e.g. [this answer](https://stackoverflow.com/questions/30026030/what-is-the-best-way-to-save-jnienv/30026231#30026231)). As for the `jobject`, you'd have to create a global reference to it at some earlier point and save it somewhere where the other function can find it. – Michael Apr 03 '21 at 10:57
  • You may want to consider using a tool like JavaCPP that abstracts away all those details: https://github.com/bytedeco/javacpp – Samuel Audet Dec 14 '21 at 02:55

0 Answers0