Damg
Damg

Reputation: 416

JNI AttachCurrentThread NULLs the jenv

I'm currently in the process of adding JNI functionality into a legacy delphi app. In a single-threaded environment everything works fine, but as soon as I move into multi-threaded environment, things start to become hairy.

My problem is that calling JavaVM^.AttachCurrentThread( JavaVM, @JEnv, nil ); returns 0, but puts the JEnv pointer to nil. I have no idea why jvm.dll should return a NULL pointer.

Is there anything I am missing?

Thank you in advance -- damg

PS:
* Environment: WinXP + JDK 1.6
* Using JNI.pas from http://www.pacifier.com/~mmead/jni/delphi/

Upvotes: 2

Views: 1254

Answers (1)

Damg
Damg

Reputation: 416

Ok, I've found the problem. I was passing a pointer to TJNIEnv and not to the packed PJNIEnv. The compiler did no typechecking and thus it failed.

Upvotes: 2

Related Questions