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. QLibrary does not load
QtWS25 Last Chance

QLibrary does not load

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 13.9k 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.
  • S Offline
    S Offline
    samsam
    wrote on last edited by
    #3

    No. is doesn't depend on another dll.

    1 Reply Last reply
    0
    • napajejenunedk0N Offline
      napajejenunedk0N Offline
      napajejenunedk0
      wrote on last edited by
      #4

      @
      QLibrary lib("C:\A.dll");
      @

      Should be:
      @
      QLibrary lib("C:\A.dll");
      @

      Use double slash in strings.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        samsam
        wrote on last edited by
        #5

        OK, I did so, but it still doesn't work.

        1 Reply Last reply
        0
        • napajejenunedk0N Offline
          napajejenunedk0N Offline
          napajejenunedk0
          wrote on last edited by
          #6

          What is the error string provided by:
          @
          QLibrary::errorString()
          @

          after you load the library?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            samsam
            wrote on last edited by
            #7

            Cannot load library C:\A.dll:

            1 Reply Last reply
            0
            • napajejenunedk0N Offline
              napajejenunedk0N Offline
              napajejenunedk0
              wrote on last edited by
              #8

              You could try with the Windows SDK's LoadLibrary function (#include <Windows.h>). Then get the error identifier using GetLastError:

              @
              #include <Windows.h>
              #include <string>
              #include <QDebug>

              std::string getLastErrorAsString();

              int main()
              {
              HMODULE libraryHandle = ::LoadLibrary( "C:\A.dll" );
              if ( libraryHandle == 0 )
              {
              const DWORD errorCode = ::GetLastError();
              qDebug() << "error: code(" << errorCode << "), description(" << getLastErrorAsString() << ')';
              }

              return 0;
              

              }

              std::string getLastErrorAsString()
              {
              //Get the error message, if any.
              DWORD errorMessageID = ::GetLastError();
              if(errorMessageID == 0)
              return "No error message has been recorded";

              LPSTR messageBuffer = nullptr;
              size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                                           NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
              
              std::string message(messageBuffer, size);
              
              //Free the buffer.
              LocalFree(messageBuffer);
              
              return message;
              

              }
              @

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #9

                Hi,

                Can you check "this":http://stackoverflow.com/questions/22354639/loading-library-with-dependency-with-qlibrary out.

                157

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  samsam
                  wrote on last edited by
                  #10

                  [quote author="napajejenunedk0" date="1401015515"]You could try with the Windows SDK's LoadLibrary function (#include <Windows.h>). Then get the error identifier using GetLastError:

                  @
                  #include <Windows.h>
                  #include <string>
                  #include <QDebug>

                  std::string getLastErrorAsString();

                  int main()
                  {
                  HMODULE libraryHandle = ::LoadLibrary( "C:\A.dll" );
                  if ( libraryHandle == 0 )
                  {
                  const DWORD errorCode = ::GetLastError();
                  qDebug() << "error: code(" << errorCode << "), description(" << getLastErrorAsString() << ')';
                  }

                  return 0;
                  

                  }

                  std::string getLastErrorAsString()
                  {
                  //Get the error message, if any.
                  DWORD errorMessageID = ::GetLastError();
                  if(errorMessageID == 0)
                  return "No error message has been recorded";

                  LPSTR messageBuffer = nullptr;
                  size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                                               NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
                  
                  std::string message(messageBuffer, size);
                  
                  //Free the buffer.
                  LocalFree(messageBuffer);
                  
                  return message;
                  

                  }
                  @[/quote]

                  the error massage is:
                  error: code <126>, description<the specified module could not be found.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MuldeR
                    wrote on last edited by
                    #11

                    Just to be sure: You are not trying to load a 64-Bit DLL from a 32-Bit process or vice versa, right? If so, it clearly cannot work.

                    Secondly, does your "A.dll" have any further dependencies? Check this with Dependency Walker, if not sure! And make sure that all required dependencies are present! Note that Windows will look for the dependencies in the directory where your EXE file is located and in some system directories (like "C:\Windows\System32"), but not in the directory where "A.dll" is located.

                    Last but not least: Putting the DLL file directly into "C:" is pretty unusual. Non-elevated processes don't have write-access there. It's even possible the Virtual Store actually copied the DLL to another place, like "C:\Users\UserName\AppData\Local\VirtualStore\A.dll" rather than "C:\A.dll". So in the Explorer it may appear to be stored at "C:\A.dll" while it fact it is not! So try loading the DLL from a more "safe" place, like your "Desktop" directory...

                    My OpenSource software at: http://muldersoft.com/

                    Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                    Go visit the coop: http://youtu.be/Jay...

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      samsam
                      wrote on last edited by
                      #12

                      Thank you very much!

                      The problem was that the dll was a 32-Bit DLL, and the process was 64.
                      I changed the dll and now its working :).

                      1 Reply Last reply
                      0

                      • Login

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