Hi all,
I tried to create a JVM instance as laid out in the examples. The JVM is never getting created. I am using Visual C++ (I need to, when the code works I will be creating a DLL that is an addon to someother piece of software).
I have posted the code below::
#include "stdafx.h"
#include "invoke2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int main(void)
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
JNIEnv *env; /* The java vm environment */
JavaVM *jvm; /* The actual jvm */
CString fname; /* The file name of the generated intermediate obj file */
JDK1_1InitArgs vm_args;
jint res;
jint vmavail;
jclass cls;
jmethodID mid;
//char classpath[4096];
bool viewerready; /* is this java viewer valid? */
vm_args.classpath=".";
vm_args.version = JNI_VERSION_1_4;
vmavail=JNI_GetDefaultJavaVMInitArgs(&vm_args);
if(vmavail < 0)
{
AfxMessageBox(" That VM version is not available. ",100,100);
viewerready=false;
jvm=NULL;
env=NULL;
}
else
{
vm_args.classpath=".";
res = JNI_CreateJavaVM(&jvm,(void **) &env,&vm_args);
if(res < 0)
{
AfxMessageBox("Could not create JVM instance. \n Check your classpath. \n 3D viewer will not be available. ",100,100);
jvm=NULL;
env=NULL;
viewerready=false;
}
else
{
cls = env->FindClass("OBJViewer");
if(cls == 0)
{
AfxMessageBox("Can't find the java OBJViewer class. ",100,100);
viewerready=false;
}
mid = env->GetMethodID(cls, "OBJViewer", "");
if(mid == 0)
{
AfxMessageBox(" java class OBJViewer has no constructor OBJViewer() ");
viewerready=false;
}
env->CallStaticVoidMethod(cls, mid);
}
}
}
return nRetCode;
}