JNI again: How do you write this cpp code in Kotlin? ```JNIEnv *env; JNI_CreateJavaVM(&jvm, (voi...
h
JNI again: How do you write this cpp code in Kotlin?
Copy code
JNIEnv *env;
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
I tried this but always get the error, the env is null:
Copy code
memScope {
  val env = alloc<JNIEnvVar>().ptr
  JNI_CreateJavaVM(jvm, env.reinterpret(), vmArgs.ptr)
  env.pointed.pointed!!.GetVersion!!(env) // GetVersion!! was null
}
`
So I guess there is an error with converting the env to
(void**)
https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html https://github.com/hfhbd/jniTest/blob/deferWorkaround/src/nativeMain/kotlin/Foo.kt
d
val env = alloc<JNIEnvVar>()
->
val env = alloc<CPointerVar<JNIEnvVar>>()
h
Wow, thank you, it works. Now I have to fix other errors 😄 Do you have any cheat sheet when to use CPointerVar or
ptr
?
d
Nope, just experience. I haven't even written kotlin native for a while now