JNI_GetCreatedJavaVMs problem (explicit or implicit link)

Hi,

I have a Java class calls C calls others java class ...

in C , i need to use JNI_GetCreatedJavaVMs with a LoadLibrary.

(Visual Studio 2005, JDK 1.6, JRE 1.6)

static JavaVM *FindCreatedJavaVM(void)

{

JavaVM *jvm = NULL;

jsize jvm_count = 0;

jint res=0;

#ifdef __STATIC_LIB_JVM

res = JNI_GetCreatedJavaVMs (&jvm, 1, &jvm_count);

#else

{

HINSTANCE hLibJVM;

typedef jint (JNICALL GetCreatedJavaVMs_t)( JavaVM**, jsize, jsize* );

GetCreatedJavaVMs_t *MyGetCreatedJavaVMs;

hLibJVM = LoadLibrary("e:/jre/bin/client/jvm.dll");

MyGetCreatedJavaVMs = (GetCreatedJavaVMs_t*)GetProcAddress( hLibJVM, "JNI_GetCreatedJavaVMs" );

res = MyGetCreatedJavaVMs(&jvm, 1, &jvm_count);

}

#endif

if (res == 0)

{

if ( jvm_count == 0 )

{

jvm = NULL;

}

}

else jvm = NULL;

return jvm;

}

/*--*/

if i use a implicit link of jvm.dll (#define __STATIC_LIB_JVM)

this example works. i find a jvm

if i use a explicit link of jvm.dll, i don't find a jvm.

hLibJVM & MyGetCreatedJavaVMs != NULL (path for jvm.dll is ok)

Where is the problem ?

Thanks you for your help

Allan

[1297 byte] By [allan_corneta] at [2007-11-27 3:40:47]
# 1

Hi,

I found the problem

in fact , i do

java -cp . MyClassJava

MyClassJava calls C (JNI_GetCreatedJavaVMs or/and CreateJavaVM) calls some others java classes.

to have JNI_GetCreatedJavaVMs , i do a explicit link of jvm.dll

in this case i load e:/jre/bin/client/jvm.dll , but the problem is that i have another jre defined in path

java -cp . MyClassJava doesn't call e:/jre/bin/java.exe but another ...

and in this , there isn't no others jvm created in this "java.exe".

and i have a crash , if i force path

e:\jre\bin\java -cp . MyClassJava , it is ok ...

then i need to check all paths possible

embedded jre, registry, path ,... and

LoadLibrary and try a JNI_GetCreatedJavaVMs until a found a jvm ...

Allan

allan_corneta at 2007-7-12 8:44:15 > top of Java-index,Java HotSpot Virtual Machine,Specifications...