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. How to get path of executable

How to get path of executable

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
3 Posts 3 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.
  • J Offline
    J Offline
    Jake Palmer
    wrote on last edited by
    #1

    How can I get the path of the executable? I want to Open a file in the same directory - the problem is that something causes the relative directory to change, so just specifying the filename can give me a FileNotFound exception. thanks, Jake ***** Jake Palmer www.duke.edu/~jp6

    T H 2 Replies Last reply
    0
    • J Jake Palmer

      How can I get the path of the executable? I want to Open a file in the same directory - the problem is that something causes the relative directory to change, so just specifying the filename can give me a FileNotFound exception. thanks, Jake ***** Jake Palmer www.duke.edu/~jp6

      T Offline
      T Offline
      Tili
      wrote on last edited by
      #2

      Its easy. use function GetModuleFileName like this char szFileName[MAX_PATH]; GetModuleFileName(NULL,szFileName,MAX_PATH); but you want to know the directory of your file you can use function GetCurrentDirectory like this char szFileName[MAX_PATH]; GetCurrentDirectory(MAX_PATH,szFileName); Secondly you may be having this problem because you are executing the file from within visual c which makes the parent folder the working directory and not the "Debug" or "Release" folder of your project. Put the file you want to access in the parent of your "Debug" folder. In my dream, I was dorwning in my §orrow§ But my §orrow§, they learned to §wim

      1 Reply Last reply
      0
      • J Jake Palmer

        How can I get the path of the executable? I want to Open a file in the same directory - the problem is that something causes the relative directory to change, so just specifying the filename can give me a FileNotFound exception. thanks, Jake ***** Jake Palmer www.duke.edu/~jp6

        H Offline
        H Offline
        Hans Georg Ulrich
        wrote on last edited by
        #3

        Since GetModuleFileName(...) has some restrictions when used under Win9x, I prefer to evaluate the public variable CWinApp::m_pszHelpFilePath.

        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