Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt dll loading failed



  • Hello, I have Qt 5.7 for MinGw 32-bit installed on my Windows 7 64-bit OS. I am trying to load programmatically a dll with the following code:

    #include "mainwindow.h"
    #include "QLibrary"
    #include "QDebug"
    #include "QString"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QLibrary myLib("ucrtbased.dll");
        myLib.load();
    
        if(!myLib.isLoaded()){
            qDebug() <<  myLib.errorString() ;
        } else {
            qDebug() << "All ok";
        }
        return a.exec();
    }
    

    and it works with some dll, like ucrtbased.dll, which under the "file" command (in terminal) appears as:

    ucrtbased.dll: PE32 executable (DLL) (Console) Intel 80386, for MS Windows
    
    

    while if I try to load the dll I want to use, which has the following format:

    mylib.dll: PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
    
    

    I get the following error from qDebug():

    "Cannot load library mylib.dll: Could not find the specified module."

    Both the libraries are in the same directory, so I believe is a format problem. Anyway, the only difference between the two is the (GUI) instead of (console) attribute, but I don't know what it means and how it could affect the loading of the library.

    Any suggestion? Thanks in advance.


  • Lifetime Qt Champion

    Hi
    Is it possible mylib.dll have dependencies on some Qt*.DLLS ?
    So when you try to load it, it fails to load those libraries.?

    You can use
    http://www.dependencywalker.com/
    to see if that is the case.

    I assume you :
    1: compiled the mylib.dll with mingw compiler
    2: have mylib.dll near the exe or it can be found via path so that
    " Could not find the specified module." do not mean , cannot find mylib.dll


  • Moderators

    In addition to what @mrjj said, be sure to check if there is such a file at all:

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        if (!QFileInfo("ucrtbased.dll").exists())
            qDebug() << "No such file";
     
        // ...
    }
    


  • I have found the problem, a silly one actually, so sorry for having you wasting time. The executable file built by Qt resides in another folder from where I was putting the dll (which I did put in the folder of the project/source files), so my program was actually not finding the dll, but ucrtbased.dll had a copy in the library_path so it was loaded anyway. I moved mydll in the exe folder and it works.

    Thanks for the support.


Log in to reply