J
James Cassidy
Can anyone please lend some assistance? I've scanned the newsgroup archives as well as the net,
but not been able to get this to work.
My code to load a jvm works from a console program, but returns -1 when used in an MFC GUI program.
The vfprintf even works in the console version, but not in the MFC version!??
static jint JNICALL my_vfprintf(FILE *fp, const char *format, va_list args)
{
char buf[1024];
_vsnprintf(buf, sizeof(buf), format, args);
return 1;
}
void CTestApp::loadJvm( void )
{
JavaVMInitArgs vm_args;
JavaVMOption options[5];
JavaVM *jvm;
JNIEnv *env;
jint res;
options[0].optionString = "-Djava.compiler=NONE";
options[1].optionString = "-Djava.class.path=c:\\j2sdk1.4.2_04\\jre\\lib\\rt.jar.";
options[2].optionString = "-Djava.library.path=c:\\j2sdk1.4.2_04\\bin";
options[3].optionString = "-verbose:jni";
options[4].optionString = "vfprintf";
options[4].extraInfo = my_vfprintf;
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 5;
vm_args.ignoreUnrecognized = JNI_TRUE;
res = JNI_CreateJavaVM( &jvm, (void **) &env, &vm_args );
if( res < 0 ) {
MessageBox( NULL, "JNI_CreateJavaVM failed.", "Error loading Java VM", MB_OK );
}
}
but not been able to get this to work.
My code to load a jvm works from a console program, but returns -1 when used in an MFC GUI program.
The vfprintf even works in the console version, but not in the MFC version!??
static jint JNICALL my_vfprintf(FILE *fp, const char *format, va_list args)
{
char buf[1024];
_vsnprintf(buf, sizeof(buf), format, args);
return 1;
}
void CTestApp::loadJvm( void )
{
JavaVMInitArgs vm_args;
JavaVMOption options[5];
JavaVM *jvm;
JNIEnv *env;
jint res;
options[0].optionString = "-Djava.compiler=NONE";
options[1].optionString = "-Djava.class.path=c:\\j2sdk1.4.2_04\\jre\\lib\\rt.jar.";
options[2].optionString = "-Djava.library.path=c:\\j2sdk1.4.2_04\\bin";
options[3].optionString = "-verbose:jni";
options[4].optionString = "vfprintf";
options[4].extraInfo = my_vfprintf;
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 5;
vm_args.ignoreUnrecognized = JNI_TRUE;
res = JNI_CreateJavaVM( &jvm, (void **) &env, &vm_args );
if( res < 0 ) {
MessageBox( NULL, "JNI_CreateJavaVM failed.", "Error loading Java VM", MB_OK );
}
}