Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt dll loading failed
Forum Updated to NodeBB v4.3 + New Features

Qt dll loading failed

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 3.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CBenussi
    wrote on 27 Sept 2016, 15:19 last edited by
    #1

    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.

    K 1 Reply Last reply 27 Sept 2016, 16:10
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 27 Sept 2016, 15:29 last edited by mrjj
      #2

      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

      1 Reply Last reply
      2
      • C CBenussi
        27 Sept 2016, 15:19

        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.

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 27 Sept 2016, 16:10 last edited by
        #3

        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";
         
            // ...
        }
        

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        3
        • C Offline
          C Offline
          CBenussi
          wrote on 28 Sept 2016, 06:58 last edited by
          #4

          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.

          1 Reply Last reply
          1

          1/4

          27 Sept 2016, 15:19

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved