Posted By:
Lee_Remick
Posted On:
Wednesday, October 16, 2002 04:33 PM
I have an ATL C++ component in large COM application that attempts to create the JVM. The facts: 1. It can always create the jdk1.3.1_02 classic version. (C:jdk1.3.1_02jre inclassicjvm.dll) 2. It cannot create the jdk1.3.1_02 hotspot or server versions. I get a fatal exception in the application or wind up in a catch block.In a prior build version we had no problems creating the JVM. We have added allot of functionality since then. 3. When I create my component from a small C++ test driver I have no problem creating any of the jvms in 1.3.1_02. 4. The ATL component has not changed in over a year. 5. The installation is correct. I have used Suns JDK and also the DI_COE JAVA2 segments to locate the jvms. I
More>>
I have an ATL C++ component in large COM application that attempts to create the JVM.
The facts:
1. It can always create the jdk1.3.1_02 classic version. (C:jdk1.3.1_02jre inclassicjvm.dll)
2. It cannot create the jdk1.3.1_02 hotspot or server versions. I get a fatal exception in the application or wind up in a catch block.In a prior build version we had no problems creating the JVM. We have added allot of functionality since then.
3. When I create my component from a small C++ test driver I have no problem creating any of the jvms in 1.3.1_02.
4. The ATL component has not changed in over a year.
5. The installation is correct. I have used Suns JDK and also the DI_COE JAVA2 segments to locate the jvms.
Is there some tuning of the VM options that can fix this problem?
Here is the way I load the jvm.
void * CJMPSJavaVM::FindCreateJavaVM(TCHAR * vmPath)
{
hinstJVMLib = LoadLibrary(vmPath);
if (NULL == hinstJVMLib)
{
return NULL;
}
return GetProcAddress(hinstJVMLib, "JNI_CreateJavaVM");
}
Here is how I use the ProcAddress returned above to create the jvm.
HRESULT CJMPSJavaVM::FinalConstruct()
{
try
{
JavaVMInitArgs vm_args;
JavaVMOption options[1];
//Dynamically build the class path from jmps registry and jar files
_bstr_t btClassPath;
BuildClassPath(btClassPath);
options[0].optionString = btClassPath;
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = JNI_TRUE;
CREATE_JVM_FUNC CreateJVM_ProcAdd;
//Use the registry to find the VM
GetRegistryPath(HKEY_LOCAL_MACHINE,
KEY_JVM_LOCATION,
KEY_JVM_DIR,
m_jvmPath);
CreateJVM_ProcAdd = (CREATE_JVM_FUNC) FindCreateJavaVM(m_jvmPath);
if ( CreateJVM_ProcAdd == NULL )
{
ATLTRACE(L"Failed to load the jvm.dll library!
");
return Error(L"Failed to load the jvm.dll library", GUID_NULL, E_FAIL);
}
GET_CREATED_JVM_FUNC GetCreatedJVM_ProcAdd;
GetCreatedJVM_ProcAdd = (GET_CREATED_JVM_FUNC) FindGetCreatedJavaVMs(m_jvmPath);
jsize bufLen = 1;
jsize nVMs = 0;
jint result = GetCreatedJVM_ProcAdd(&m_jvm, bufLen, &nVMs);
if (result!=0 || !m_jvm)
{
m_status = CreateJVM_ProcAdd (&m_jvm, (void **) &m_env, &vm_args);
if ( m_status != JNI_OK )
{
ATLTRACE(L"Failed to create the Java VM!
");
JavaErrorTrace(m_status);
return Error(L"Failed to create the Java VM", GUID_NULL, E_FAIL);
}
}
m_ThreadID = GetCurrentThreadId();
return S_OK;
}
.
<<Less