Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » LoadLibrary("C:\\Program Files\\Java\\jdk-12.0.2\\bin\\server\\jvm.dll");
LoadLibrary("C:\\Program Files\\Java\\jdk-12.0.2\\bin\\server\\jvm.dll"); [message #1809700] Sat, 20 July 2019 22:27
Scott Overmyer is currently offline Scott OvermyerFriend
Messages: 1
Registered: July 2019
Junior Member
This statement fails every time. The DLL is there. It's referenced in the Linker preferences (MinGW). But LoadLibrary fails. Any ideas? Here's the entire C++ file:

//============================================================================
// Name : CallingJava.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <windows.h>
#include <iostream>
#include <jni.h>
#include <string>
using namespace std;


int main() {
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
//================== prepare loading of Java VM ============================
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
options[0].optionString = (char*) "-Djava.class.path=."; // where to find java .class
vm_args.version = JNI_VERSION_1_6; // minimum Java version
vm_args.nOptions = 1; // number of options
vm_args.options = options;
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
//=============== load and initialize Java VM and JNI interface =============

HINSTANCE hVM = LoadLibrary("C:\\Program Files\\Java\\jdk-12.0.2\\bin\\server\\jvm.dll");
if (hVM == NULL)
{
cout << "hVM returned null. could not load dll" << endl;
DWORD dwe = GetLastError();
cout << "dw2=" << dwe << endl;
return -1;
}
typedef jint (CALLBACK *fpCJV)(JavaVM**, void**, JavaVMInitArgs*);
fpCJV CreateJavaVM = (fpCJV)::GetProcAddress(hVM, "JNI_CreateJavaVM");
jint res = CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res != JNI_OK) {
// TO DO: error processing...
cin.get();
exit(EXIT_FAILURE);
}

//=============== Display JVM version =======================================
cout << "JVM load succeeded: Version ";
jint ver = env->GetVersion();
cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << endl;

// TO DO: add the code that will use JVM <============ (see next steps)

jvm->DestroyJavaVM();
cin.get();
return 0;
}


Previous Topic:How to install plugin manually? (SOLVED)
Next Topic:Error running eclipse project in internal Tomcat
Goto Forum:
  


Current Time: Mon Oct 21 04:40:33 GMT 2019

Powered by FUDForum. Page generated in 0.02861 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top