Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

LoadLibrary from C program, error 126 (solution)

843798Nov 15 2007
I ran into this problem while trying to start a JVM from a win32 C program. I didn't see similar postings and thought this might save somebody some debugging time.

I have a configuration file that contains:
jvm_lib=C:\program files\Java\jdk1.5.0_06\jre\bin\client\jvm.dll

I then read the configuration file using fgets(), and store the value portion of the property into
char * jvm_lib
I left the C code details out.

When I call Load Library, it fails with error 126.
This is ERROR_MOD_NOT_FOUND
The specified module could not be found.

And in the code, it looks like:
    if((handle = LoadLibrary(prop_jvm_lib)) == 0)
    {
        DWORD errorCode = GetLastError();
        LogErrorMessage("The Java Runtime Library could not be loaded, errorCode=" + errorCode);
    }
So how can this be if the path in my configuration file is correct? I verified that the absolute path to jvm.dll truly exists by using the "dir" command.

Well, the problem is that when I did the fgets(), C reads in the line-feed or carriage-return character, so to Windows, the path
C:\program files\Java\jdk1.5.0_06\jre\bin\client\jvm.dllY
where Y is the extra character
does not exist. Hence, the 126 error.

So be sure to remove that extra character before calling LoadLibrary.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 13 2007
Added on Nov 15 2007
0 comments
746 views