C# and native interop with JNI
So I've been tinkering with this personal project of mine to try to get C# to interop with Java using JNI (Java Native Interface). This project relies heavily on unmanaged wrappers for JNI calls that I call later using C# and DllInterop.
Here is my issue, After the native call to JNI_CreateJavaVM() and returning the pointers to the JVM and ENV (pointer to native method interface) back to the C# managing object everything appears fine and working as expected. JVM initialized, I've got pointers to the important structures to create Java classes on hand and ready, but when i decide to utilize the jvm pointer in a very simple case , to destroy it, I'm getting system AccessViolation Exception.
At first i thought this was happening due to a silly mistake on my end where i wasn't allocating the structs on the heap, so when i exit the native function call the memory addresses returned are invalid, but I am now using malloc() which should store the structs on the heap and I received the same error. Is there something I'm missing when passing void pointers in C# to native function calls?
Please let me know if im not very clear, I'm self taught and I'm not the best at conveying information. I can share code if it'll help.
0 Replies