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. Library Path
Forum Update on Monday, May 27th 2025

Library Path

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.5k 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.
  • R Offline
    R Offline
    redlars
    wrote on last edited by
    #1

    How can I inside a library determine the location of the library on the harddisk?

    Using below code determines the application path which in this case is not related to the library path.
    @
    QString path = QCoreApplication::applicationDirPath();
    @

    Using Windows XP SP3 and Qt 4.7.1.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      francomartins
      wrote on last edited by
      #2

      i'm usyng in main.cpp:
      @
      #ifdef Q_OS_WIN32
      QString env = getenv("SYSTEMROOT");
      QCoreApplication::addLibraryPath(env+"\system32");
      #endif
      @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redlars
        wrote on last edited by
        #3

        Thanks for the reply but not exactly what I need.

        Say I develop a library and install it on a WinXP computer at a location unknown to the library itself. The location of the library can be anywhere or the harddisk.

        Say an application then loads the library into its memory.

        Inside the library, in the constructor of the class MySuperClass I would like to determine the location of the library. How can I do that?

        There is no correlation between the location of the application and library.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stima_ua
          wrote on last edited by
          #4

          If you do not know where is the thing you're looking for it. You can recursive/iterating search for your dll on all hard disk.

          But I think better put dll where you know.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            redlars
            wrote on last edited by
            #5

            Thanks for the reply.

            Searching for the library could be an option but is time consuming and could return wrong path if multiple files exist with same name.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stima_ua
              wrote on last edited by
              #6

              If you need not crossplatform solution u can:

              @
              //add to header file
              extern "C" IMAGE_DOS_HEADER __ImageBase;
              #define THIS_MODULE_HINSTANCE reinterpret_cast<HINSTANCE>(&__ImageBase)

              //Then
              ::GetModuleFileName(THIS_MODULE_HINSTANCE, szBuffer, MAX_PATH)
              @
              "token from rsdn.ru":http://www.rsdn.ru/forum/winapi/261670.aspx

              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