Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Knowing the directory in which an App resides

Knowing the directory in which an App resides

Scheduled Pinned Locked Moved C / C++ / MFC
questionwindows-admin
9 Posts 6 Posters 0 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.
  • 0 Offline
    0 Offline
    0v3rloader
    wrote on last edited by
    #1

    Hello, How can I know the path of a running app without recurring to neither registry entries nor to an .INI file ? I have been checking CWinApp for a function or variable member but was unable to find one... Any suggestions? David BTW, m_pszExeName/m_pszAppName in CWinApp do not retrieve the path...

    M F 2 Replies Last reply
    0
    • 0 0v3rloader

      Hello, How can I know the path of a running app without recurring to neither registry entries nor to an .INI file ? I have been checking CWinApp for a function or variable member but was unable to find one... Any suggestions? David BTW, m_pszExeName/m_pszAppName in CWinApp do not retrieve the path...

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      GetModuleFileName


      Maximilien Lincourt Your Head A Splode - Strong Bad

      1 Reply Last reply
      0
      • 0 0v3rloader

        Hello, How can I know the path of a running app without recurring to neither registry entries nor to an .INI file ? I have been checking CWinApp for a function or variable member but was unable to find one... Any suggestions? David BTW, m_pszExeName/m_pszAppName in CWinApp do not retrieve the path...

        F Offline
        F Offline
        Fernando A Gomez F
        wrote on last edited by
        #3

        There is this Windows API function: GetCurrentDirectory. GetModuleFileName will only give you the file name, like "module.dll" instead of "C:\Program Files\Your Company\Your Product\bin\module.dll", the complete path. The prototype is as follows: DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer); Greetings. I know there's something so dear to me, beyond words, beautiful feelings in my soul, sounds I've heard like humming birds in a dream. That mystical one I knew is returned, lulling me with those raincloud eyes, taking me and melting my heart away.

        J B 2 Replies Last reply
        0
        • F Fernando A Gomez F

          There is this Windows API function: GetCurrentDirectory. GetModuleFileName will only give you the file name, like "module.dll" instead of "C:\Program Files\Your Company\Your Product\bin\module.dll", the complete path. The prototype is as follows: DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer); Greetings. I know there's something so dear to me, beyond words, beautiful feelings in my soul, sounds I've heard like humming birds in a dream. That mystical one I knew is returned, lulling me with those raincloud eyes, taking me and melting my heart away.

          J Offline
          J Offline
          John M Drescher
          wrote on last edited by
          #4

          Wrong. GetCurrentDirectory will not always return the directory that the executable is in. You can not assume that it does as an a shortcut could change the working directory, the program can change the working directory or the user could launch the program from a command window using the full path. In each case GetCurrentDirectory will not be the directory that the program resides. GetModuleFileName returns the correct result. Here is the doc: GetModuleFileName The GetModuleFileName function retrieves the full path and file name for the file containing the specified module. John

          1 Reply Last reply
          0
          • F Fernando A Gomez F

            There is this Windows API function: GetCurrentDirectory. GetModuleFileName will only give you the file name, like "module.dll" instead of "C:\Program Files\Your Company\Your Product\bin\module.dll", the complete path. The prototype is as follows: DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer); Greetings. I know there's something so dear to me, beyond words, beautiful feelings in my soul, sounds I've heard like humming birds in a dream. That mystical one I knew is returned, lulling me with those raincloud eyes, taking me and melting my heart away.

            B Offline
            B Offline
            BlackDice
            wrote on last edited by
            #5

            I use GetModuleFileName() and it returns the whole path for me. In the app I wrote I use this to append a "\\temp" to the end of it for a call to CreateDirectory to create a temp folder in the same folder where the app resides. So as far as I know GetModuleFileName returns the whole path. I have a call to it like this in my app: ::GetModuleFileName(NULL,szPath,512); where 'szPath' is declared char szPath[512]; [insert witty comment here] bdiamond :zzz:

            D 1 Reply Last reply
            0
            • B BlackDice

              I use GetModuleFileName() and it returns the whole path for me. In the app I wrote I use this to append a "\\temp" to the end of it for a call to CreateDirectory to create a temp folder in the same folder where the app resides. So as far as I know GetModuleFileName returns the whole path. I have a call to it like this in my app: ::GetModuleFileName(NULL,szPath,512); where 'szPath' is declared char szPath[512]; [insert witty comment here] bdiamond :zzz:

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              bdiamond wrote: ::GetModuleFileName(NULL,szPath,512); It's not a good idea to use constants like this. If the size of your variable ever changed, you could easily miss one. Use the sizeof operator instead.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              B 1 Reply Last reply
              0
              • D David Crow

                bdiamond wrote: ::GetModuleFileName(NULL,szPath,512); It's not a good idea to use constants like this. If the size of your variable ever changed, you could easily miss one. Use the sizeof operator instead.


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                B Offline
                B Offline
                BlackDice
                wrote on last edited by
                #7

                sorry, but you know from experience that I'm not the brightest guy around:) Is this what you're saying I should do? char szPath[512]; ::GetModuleFileName(NULL,szPath,sizeof(szPath)); [insert witty comment here] bdiamond :zzz:

                D 1 Reply Last reply
                0
                • B BlackDice

                  sorry, but you know from experience that I'm not the brightest guy around:) Is this what you're saying I should do? char szPath[512]; ::GetModuleFileName(NULL,szPath,sizeof(szPath)); [insert witty comment here] bdiamond :zzz:

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  bdiamond wrote: Is this what you're saying I should do? Correct.


                  "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                  B 1 Reply Last reply
                  0
                  • D David Crow

                    bdiamond wrote: Is this what you're saying I should do? Correct.


                    "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                    B Offline
                    B Offline
                    BlackDice
                    wrote on last edited by
                    #9

                    cool. Thanks [insert witty comment here] bdiamond :zzz:

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups