passing JNIEnv to VB, then back to C++ (standard DLL)
843829Jul 25 2006 — edited Jul 25 2006I have 2 methods I expose in my C++ DLL to my VB app:
1. init_JVM( ) which I want to return a JNIEnv reference. This method is called once from my VB app.
2. convert_Image( ) which passes the JNIEnv object as a parameter back to the C++ DLL. This method is called many times from VB.
So, essentially, my VB code I have:
Declare Function init_JVM Lib "convert.dll" () As Object
Declare Sub convert_Image Lib "convert.dll" (ByRef lpJNIEnv As Any, ByVal strTiffSourcePath As String, ByVal strError As String)
Sub Main( )
Dim oEnv As Object
'*** Initialization - create JVM
Set oEnv = init_JVM()
For iNum = 0 to nCount
convert_Image(oEnv)
Next
End Sub
This is what my C++ looks like:
extern "C" JNIEXPORT JNIEnv *JNICALL init_JVM()
{
JNIEnv *env;
// code that creates JVM...
return env;
}
extern "C" JNIEXPORT void JNICALL convert_Image(JNIEnv *env)
{
jclass convertClass;
// BLOWS UP ON THIS CALL
convertClass = env->FindClass("TConvert");
// the rest of the code
}
So, TConvert, is a java class. It blows up with an "Unhandled exception" error the first time it hits that line. Everything used to worked well if I didn't pass the env (when everything was in 1 method). But I had to split into 2 methods so that in my VB, I want to be able to only create the JVM once and then call the convert_Image as many times as I need to.
Please help. I think this is just a matter of being able to pass the JNIEnv correctly. What should the object types be in the declare statements in VB?
Thanks in advance.
Ya-Tin