Forum Stats

  • 3,838,700 Users
  • 2,262,394 Discussions
  • 7,900,737 Comments

Discussions

AttachCurrentThread not setting 'env' parameter

573044
573044 Member Posts: 28
edited May 4, 2011 1:13PM in Java Native Interface (JNI)
Here are a bunch of snippets of my code (written in Pascal). I tried to grab all of the important parts - let me know if I missed anything.
//type declarations
PJavaVM  = ^JavaVM; 
PJNIEnv = ^JNIEnv;
...
//global variable
var
  MainJVM : JavaType.PJavaVM;
...
// Setting the 'MainJVM' variable (from the main thread) within a procedure
var
  env : JavaType.PJNIEnv
...
env^^.GetJavaVM(env,MainJVM);
...
// Attaching MainJVM's thread to 'env' (which isn't working) within a procedure
var
  env : JavaType.PJNIEnv;
...
MainJVM^^.AttachCurrentThread(MainJVM,@env,nil)
Everything seems to be working up to the 'AttachCurrentThread' line. That line returns a 0 but the value of 'env' isn't updated.

Thanks!

Answers

  • 802316
    802316 Member Posts: 532
    I have never tried this from Pascal (haven't used it in 22 years ;) ), but in C the parameter type is
    jint AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args);
    So p_env should be a pointer to a pointer to a JNIEnv.

    Is that the case here?
    802316
  • 573044
    573044 Member Posts: 28
    I believe it is.
    env is of type "PJNIEnv" which is "^JNIEnv" (a pointer to JNIEnv).

    AttachCurrentThread passes "@env" which is the address of "env". So it should be a pointer to a pointer to JNIEnv. Right? (I think so)
This discussion has been closed.