Hey all,
I have a C++ app which I successfully used about a year ago to put up a Java dialog from within QuarkXPress, which has a C/C++ API. I got it out and rebuilt it and ran it, and I am now getting an Access Violation (0xC0000005) exception in JVM.dll somewhere. I am getting the exception in the CallStaticVoidMethod() call. Here is the relevant snippet from the method I am using: if anyone can spot anything obviously amiss, I would appreciate knowing about it! (This snippet borrows heavily from the "invoke.c" example program in the JNI tutorial.)
JavaVM *jvm;
jint res;
jclass cls;
jmethodID mid;
jthrowable except = NULL;
JavaVMInitArgs vm_args;
JavaVMOption options[2];
char newcpath[512];
char newlibpath[512];
sprintf (newcpath, "-Djava.class.path=.;C:\\Program Files\\QuarkXpress 4.0\\XTENSION");
sprintf (newlibpath, "-Djava.library.path=.;C:\\Program Files\\QuarkXpress 4.0\\XTENSION");
options[0].optionString = newcpath;
options[1].optionString = newlibpath;
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res == JNI_EEXIST)
{
JavaVM *jvms[1];
jsize nVMs;
res = JNI_GetCreatedJavaVMs(jvms, 1, &nVMs);
jvm = jvms[0];
jvm->AttachCurrentThread((void**)&env, NULL);
}
else if (res < 0)
{
return UNKNOWN_ERROR;
}
cls = env->FindClass(g_javaName);
if (cls == 0)
{
checkException();
destroy(jvm);
return MISSING_CLASS;
}
mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
if (mid == 0)
{
destroy(jvm);
return MISSING_METHOD;
}
env->CallStaticVoidMethod(cls, mid);