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. Error when trying to load DLL with QLibrary
QtWS25 Last Chance

Error when trying to load DLL with QLibrary

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 2.6k Views
  • 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.
  • L Offline
    L Offline
    Linhares
    wrote on 17 May 2022, 13:13 last edited by
    #1

    I'm using Qt5 and I want to work with a DLL file that I know is fully functional and which I can even use with other programs on my computer with no problems.

    However, when I try to load it in my program using QLibrary, I get an error message.

    Here's the .cpp file:

    #include <QLibrary>
    #include <QDebug>
    
    myObject::myObject()
    {
        QLibrary myLibrary("./myDll");
        myLibrary.load();
        if(myLibrary.isLoaded())
            qDebug() << "It worked!";
        else
        {
            qDebug() << myLibrary.errorString();
        }
    }
    

    When I run this code, I get this error message:

    "Cannot load library .\myDll: Unknown error 0x000000c1."

    I've run Dependency Walker and I get a lot of yellow flags. However, I can't understand how I've been using this DLL with other (3rd party) programs on the same computer without any problems.

    I contacted the developer of the DLL and he told me this library is a plain C (not C++) 32-bit library, and that perhaps I should adjust some of the compiler options. If this is the case, which options should I change?

    J J 2 Replies Last reply 17 May 2022, 13:20
    0
    • L Linhares
      17 May 2022, 13:13

      I'm using Qt5 and I want to work with a DLL file that I know is fully functional and which I can even use with other programs on my computer with no problems.

      However, when I try to load it in my program using QLibrary, I get an error message.

      Here's the .cpp file:

      #include <QLibrary>
      #include <QDebug>
      
      myObject::myObject()
      {
          QLibrary myLibrary("./myDll");
          myLibrary.load();
          if(myLibrary.isLoaded())
              qDebug() << "It worked!";
          else
          {
              qDebug() << myLibrary.errorString();
          }
      }
      

      When I run this code, I get this error message:

      "Cannot load library .\myDll: Unknown error 0x000000c1."

      I've run Dependency Walker and I get a lot of yellow flags. However, I can't understand how I've been using this DLL with other (3rd party) programs on the same computer without any problems.

      I contacted the developer of the DLL and he told me this library is a plain C (not C++) 32-bit library, and that perhaps I should adjust some of the compiler options. If this is the case, which options should I change?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 17 May 2022, 13:20 last edited by
      #2

      @Linhares said in Error when trying to load DLL with QLibrary:

      QLibrary myLibrary("./myDll");

      You are using a relative path: are you sure the lib is in the current working directory?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply 17 May 2022, 13:34
      2
      • L Linhares
        17 May 2022, 13:13

        I'm using Qt5 and I want to work with a DLL file that I know is fully functional and which I can even use with other programs on my computer with no problems.

        However, when I try to load it in my program using QLibrary, I get an error message.

        Here's the .cpp file:

        #include <QLibrary>
        #include <QDebug>
        
        myObject::myObject()
        {
            QLibrary myLibrary("./myDll");
            myLibrary.load();
            if(myLibrary.isLoaded())
                qDebug() << "It worked!";
            else
            {
                qDebug() << myLibrary.errorString();
            }
        }
        

        When I run this code, I get this error message:

        "Cannot load library .\myDll: Unknown error 0x000000c1."

        I've run Dependency Walker and I get a lot of yellow flags. However, I can't understand how I've been using this DLL with other (3rd party) programs on the same computer without any problems.

        I contacted the developer of the DLL and he told me this library is a plain C (not C++) 32-bit library, and that perhaps I should adjust some of the compiler options. If this is the case, which options should I change?

        J Online
        J Online
        JonB
        wrote on 17 May 2022, 13:25 last edited by JonB
        #3

        @Linhares said in Error when trying to load DLL with QLibrary:

        "Cannot load library .\myDll: Unknown error 0x000000c1."

        (Additional to @jsulm.) Most (in fact I think it is mandatory?) Windows DLL files end in .DLL ... ?

        EDIT
        Given the error Cannot load library .\myDll: Unknown error 0x000000c1 that might it is found, somehow, but is "not acceptable". Google dll Unknown error 0x000000c1, seems to only come from Qt programs, e.g. see Cannot load library *.dll Unknown error 0x000000c1

        The error list you need is here. The symbolic name for that error is ERROR_BAD_EXE_FORMAT, and the error message is <filesoandso> is not a valid Win32 application. The DLL you're trying to open is either corrupt, or - most likely - it is for a different architecture. If you're compiling for 32 bits, use 32-bit DLLs. If you're compiling for 64 bits, use 64-bit DLLs.

        If the developer says it is 32-bit are you compiling your Qt program 32-bit or 64-bit? :)

        1 Reply Last reply
        1
        • J jsulm
          17 May 2022, 13:20

          @Linhares said in Error when trying to load DLL with QLibrary:

          QLibrary myLibrary("./myDll");

          You are using a relative path: are you sure the lib is in the current working directory?

          L Offline
          L Offline
          Linhares
          wrote on 17 May 2022, 13:34 last edited by
          #4

          @jsulm Yes, the lib is in the folder. From the error message, I understand the program can find the lib, but it can't load it correctly.

          J 1 Reply Last reply 17 May 2022, 13:45
          0
          • L Linhares
            17 May 2022, 13:34

            @jsulm Yes, the lib is in the folder. From the error message, I understand the program can find the lib, but it can't load it correctly.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 17 May 2022, 13:45 last edited by
            #5

            @Linhares Take a look at this: https://stackoverflow.com/questions/61080829/cannot-load-library-dll-unknown-error-0x000000c1
            Is it possible that this DLL is built for a different architecture? Like your app is x86_64, but the lib x86.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Linhares
              wrote on 17 May 2022, 13:52 last edited by
              #6

              @JonB this is the kit I've been using:
              c72cc0c9-086d-473b-90ca-8409e926f6ff-image.png
              My understanding is that it's 32-bit compiler.

              @jsulm how do I check my app's architecture?

              J 1 Reply Last reply 17 May 2022, 13:58
              0
              • L Linhares
                17 May 2022, 13:52

                @JonB this is the kit I've been using:
                c72cc0c9-086d-473b-90ca-8409e926f6ff-image.png
                My understanding is that it's 32-bit compiler.

                @jsulm how do I check my app's architecture?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 17 May 2022, 13:58 last edited by
                #7

                @Linhares If that is the Kit you are using to build your app then you're building a 32bit app.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  Linhares
                  wrote on 17 May 2022, 14:07 last edited by
                  #8

                  @jsulm Ok, so I'm using the correct architecture, right?

                  J 1 Reply Last reply 17 May 2022, 15:07
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on 17 May 2022, 14:53 last edited by
                    #9

                    Can you try to build and link to that dll instead using QLibrary? You may get a more informative link error than what you are getting when loading with QLibrary.

                    1 Reply Last reply
                    1
                    • L Linhares
                      17 May 2022, 14:07

                      @jsulm Ok, so I'm using the correct architecture, right?

                      J Online
                      J Online
                      JonB
                      wrote on 17 May 2022, 15:07 last edited by JonB
                      #10

                      @Linhares
                      Although you have said "Yes, the lib is in the folder", and presumably you claim the relative path ./myDll finds it successfully, you still have not said anything about my

                      Most (in fact I think it is mandatory?) Windows DLL files end in .DLL ... ?

                      ? [Oh, are we supposed to guess that you are in fact not using literal ./myDll but rather ./something.dll??] You could always do a QFileInfo on whatever you pass to make sure....

                      Otherwise @mchinand's suggestion of quickly making your application actually try to link with thedll.lib (you do have that?) by calling a function in it from your Qt program is a good idea to get a better error message,

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        Linhares
                        wrote on 23 May 2022, 14:27 last edited by
                        #11

                        It turned out that I noticed I was being fooled by Qt Creator. Although the settings showed MSVC 32-bit as default, it was not installed. Hence, I was running a 64-bit compiler and thinking I was using a 32-bit one.
                        Thank you guys for the help with this!

                        1 Reply Last reply
                        0
                        • C Christian Ehrlicher referenced this topic on 19 Aug 2024, 15:30

                        4/11

                        17 May 2022, 13:34

                        7 unread
                        • Login

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