Lucas Breeden
Lucas Breeden

Reputation: 46

LoadLibrary on jvm.dll fails with error code 183

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.

Upvotes: 0

Views: 947

Answers (1)

selbie
selbie

Reputation: 104559

Try this instead:

HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL)
   jvmDLL = GetModuleHandle("jvm.dll");
}

Upvotes: 1

Related Questions