Thursday, 22 August 2013

Using JVM in C++ (VS2005)

Using JVM in C++ (VS2005)

I ham trying to load JVM in C++. My code is as under. The problem is that
as soon as the code reaches JNI_CreateJavaVM it closes VS (probably is
crashing) and does not let me see the value of ret
void PRISAdapterDlg::create_vm()
{
JavaVM ** jvm;
JNIEnv *env; /* pointer to native method interface */
JavaVMInitArgs vm_args; /* JDK 1.1 VM initialization arguments */
JavaVMOption options;
options.optionString = "-Djava.class.path=C:\\Secure\\Source";
//JNI_GetDefaultJavaVMInitArgs(&vm_args);
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates
version 1.6
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;
HMODULE jvm_dll = LoadLibrary("C:\\Program
Files\\Java\\jdk1.6.0_23\\jre\\bin\\server\\jvm.dll");
/// You might check the GetLastError() here after the LoadLibrary()
if(jvm_dll == NULL)
{
printf("can't load dll\n");
exit(1);
}
JNI_CreateJavaVM_ptr = (JNI_CreateJavaVM_func)GetProcAddress(jvm_dll,
"JNI_CreateJavaVM");
/// You might check the GetLastError() here
if(JNI_CreateJavaVM_ptr == NULL)
{
printf("can't load function\n");
exit(1);
}
int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);
if(ret < 0)
printf("\nUnable to Launch JVM\n");
}

No comments:

Post a Comment