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
Forum Updated to NodeBB v4.3 + New Features

Error when trying to load DLL with QLibrary

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 3.1k Views 1 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.
  • L Linhares

    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?

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on 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
    2
    • L Linhares

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      • jsulmJ jsulm

        @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 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.

        jsulmJ 1 Reply Last reply
        0
        • L Linhares

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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 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?

            jsulmJ 1 Reply Last reply
            0
            • L Linhares

              @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?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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 last edited by
                #8

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

                JonBJ 1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mchinand
                  wrote on 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

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

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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 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
                      • Christian EhrlicherC Christian Ehrlicher referenced this topic on

                      • Login

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