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. Obtaining an Application's Folder

Obtaining an Application's Folder

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
5 Posts 4 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.
  • R Offline
    R Offline
    rbrunton
    wrote on last edited by
    #1

    I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron

    S J T R 4 Replies Last reply
    0
    • R rbrunton

      I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron

      S Offline
      S Offline
      Scozturk
      wrote on last edited by
      #2

      Well I dont use MFC I only know the API way so: you can get it like this: [code] char path[_MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), path, _MAX_PATH ); [/code] Path holds the full address of your exe like "C:\Program Files\Program\test.exe" just delete text.exe from it and its done... Well... I am a beginner ...

      1 Reply Last reply
      0
      • R rbrunton

        I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron

        J Offline
        J Offline
        Jack Puppy
        wrote on last edited by
        #3

        You might want to check this article out. (in particular, the last 3/4 topics) How To Write a Windows XP Application That Stores User and Application Data in the Correct Location by Using Visual C++ .NET You could run into access problems when users run the app from a limited account in the Program Files\App folder.

        Painted on the side of a dog trainer's van: SIT HAPPENS

        1 Reply Last reply
        0
        • R rbrunton

          I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          Check if this code is of any help :- //========================= // Get Current Path //========================= CString szCurrentDirectory; { CString csPath; //==================== // Get File Path //==================== ::GetModuleFileName(NULL,csPath.GetBuffer(MAX_PATH),MAX_PATH); csPath.ReleaseBuffer(); //==================== //Get current Directory //==================== szCurrentDirectory=csPath.Left(csPath.ReverseFind('\\')); }

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta VC Forum Q&A :- I/ IV

          1 Reply Last reply
          0
          • R rbrunton

            I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron

            R Offline
            R Offline
            rbrunton
            wrote on last edited by
            #5

            Thanks to all who responded. Problem solved! Ron

            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