J
justdoit693
I'm trying to host the JVM in a simple windows app but when I run the app
the JNI_CreateJavaJVM() call fails with -1 every time...at first, it
couldn't find the jvm.dll but I moved a copy of that into my .exe directory
and that solved that problem...is there something else I need to do with the
DLL's?
I've seen dozens of samples of this but nothing that tells me what to do for
JNI_VERSION_1_4...any help is appreciated.
Here is my code:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
jint res;
jclass cls;
jmethodID mid;
jobjectArray args;
memset(&vm_args,0,sizeof(vm_args)) ;
vm_args.version = JNI_VERSION_1_4 ;
vm_args.nOptions = 1;
options[0].optionString = "-Djava.class.path=d:\\MyApp.jar";
vm_args.options = options;
vm_args.ignoreUnrecognized = true;
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args) ;
if (res < 0) {
MessageBox(NULL,"Failed to create JVM","Java Error",MB_OK) ;
return 0 ;
}
cls = env->FindClass("MyProg") ;
if (cls == 0) {
MessageBox(NULL,"Failed to find MyProg","Java Error",MB_OK) ;
return 0 ;
}
mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/StringV");
if (mid == 0) {
MessageBox(NULL,"Can't find MyProg.main()","Java Error",MB_OK) ;
return 0 ;
}
args = env->NewObjectArray(0,env->FindClass("java/lang/String"), NULL);
if (args == 0) {
MessageBox(NULL,"Out of memory","MyProg",MB_OK);
return 0 ;
}
env->CallStaticVoidMethod(cls, mid, args);
jvm->DestroyJavaVM();
return 0;
}
the JNI_CreateJavaJVM() call fails with -1 every time...at first, it
couldn't find the jvm.dll but I moved a copy of that into my .exe directory
and that solved that problem...is there something else I need to do with the
DLL's?
I've seen dozens of samples of this but nothing that tells me what to do for
JNI_VERSION_1_4...any help is appreciated.
Here is my code:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
jint res;
jclass cls;
jmethodID mid;
jobjectArray args;
memset(&vm_args,0,sizeof(vm_args)) ;
vm_args.version = JNI_VERSION_1_4 ;
vm_args.nOptions = 1;
options[0].optionString = "-Djava.class.path=d:\\MyApp.jar";
vm_args.options = options;
vm_args.ignoreUnrecognized = true;
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args) ;
if (res < 0) {
MessageBox(NULL,"Failed to create JVM","Java Error",MB_OK) ;
return 0 ;
}
cls = env->FindClass("MyProg") ;
if (cls == 0) {
MessageBox(NULL,"Failed to find MyProg","Java Error",MB_OK) ;
return 0 ;
}
mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/StringV");
if (mid == 0) {
MessageBox(NULL,"Can't find MyProg.main()","Java Error",MB_OK) ;
return 0 ;
}
args = env->NewObjectArray(0,env->FindClass("java/lang/String"), NULL);
if (args == 0) {
MessageBox(NULL,"Out of memory","MyProg",MB_OK);
return 0 ;
}
env->CallStaticVoidMethod(cls, mid, args);
jvm->DestroyJavaVM();
return 0;
}