简体   繁体   中英

LoadLibraryA fails with module not found, but the filename is correct

I am trying to load a dll like this:

dll_handle = LoadLibraryA(QString("%1\\module.dll")
                        .arg(QApplication::applicationDirPath().replace("/", "\\"))
                        .toLocal8Bit().data());

The resulting filename that I pass to LoadLibraryA is correct, the file exists and is readable by the process. What is the problem?

GetLastError reports 126, ie ERROR_MOD_NOT_FOUND . Clearly a module cannot be found.

There are two obvious causes for this:

  1. The module you are trying to load cannot be found.
  2. The module you are trying to load can be found, but one of the modules that it depends on cannot be found.

I would recommend debugging this with Dependency Walker in profile mode. This will monitor your app at runtime and tell you precisely which module cannot be found.

Finally, in this day and age, you really should be opting for LoadLibraryW .

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