I'm trying to use JNI in C++ to call a method from Java.
I have tried this on a console application and it worked, but when I switch to a DLL that is loaded in any application, it fails with error "ERROR_ALREADY_EXISTS"
HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL) {
int error = GetLastError(); // this returns 183
}
This works perfectly fine on anything but a DLL injected into any application. It shouldn't be null.
Try this instead:
HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL)
jvmDLL = GetModuleHandle("jvm.dll");
}