Tamás Szelei
Tamás Szelei

Reputation: 23961

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?

Upvotes: 1

Views: 2552

Answers (1)

David Heffernan
David Heffernan

Reputation: 613412

GetLastError reports 126, i.e. 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.

Upvotes: 9

Related Questions