简体   繁体   中英

Unable to load jvm.dll using LoadLibrary

One of our customers is having an issue with our application where it is unable to load the jvm.dll. We install a JRE with our software and so the jvm.dll is the same one that works for all of our other customers. Here's the code:

HMODULE MyApplication::GetJVMDll(char* szJavaHome)
{
    HMODULE hLibrary;
    char szPath[2048];

        strcpy_s(szPath,2048,szJavaHome);   
    #if defined( _WIN64 )   
        strcat_s(szPath, 2048,"\\bin\\msvcrt.dll"); 
    #else
        strcat_s(szPath, 2048,"\\bin\\msvcr71.DLL");    
    #endif

    hLibrary = LoadLibrary (szPath);
    if (!hLibrary) {
            return NULL;
    }
    strcpy_s(szPath,2048,szJavaHome);
    strcat_s(szPath, 2048,"\\bin\\server\\JVM.DLL");

    hLibrary = LoadLibrary (szPath);
    if (hLibrary) {
            return hLibrary;
    }

    printErrorMessage(GetLastError());

    return NULL;
}

As I said, the above code works for all our customers except one. The msvcrt.dll is being loaded successfully, but jvm.dll is not. The error returned by GetLastError() is 127. Anyone know why LoadLibrary would be failing for this customer?

From http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

ERROR_PROC_NOT_FOUND 127 (0x7F) The specified procedure could not be found.

In this snippet:

strcpy_s(szPath,2048,szJavaHome);

Could it be possible that szPath + szJavaHome goes beyond the 2048 limit? In which case the loading of the library would fail.

An other possibility: Depending on the way you retrieve the szJavaHome , and the meaning of that variable; if it is just the %JAVA_HOME% environment variable, then maybe checking if it contains a trailing slash could be helpful.

Last possibility, check what dependencies this jvm.dll have. It may be that one of these transitive dependencies cannot load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM