CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    123

    Directory of application

    How do I get the directory of the .exe application? It is not necessarily the current working directory because the project file may have been opened by double-clicking? I need to get a path for other text files that are in the application directory.

  2. #2
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496
    Check GetModuleFileName
    Har Har

  3. #3
    Join Date
    Dec 2002
    Location
    God's own country
    Posts
    201
    Use GetCurrentDirectory API

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    As the first reply mentioned, use GetModuleFileName().

    It is explained in the FAQ at :

    http://www.codeguru.com/forum/showth...hreadid=231171

  5. #5
    Join Date
    Apr 1999
    Posts
    123
    Thanks. GetModuleFileName works.

    It is odd that when I run the application from the developer environment I get long file names and when I run it by double-clicking on the project file, I get short file names. Anyway, it works.

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244
    Something like this:
    Code:
    bool CAbcDlg::GetAppDirectory( CString& strAppDir )
    {
       bool bRet        = false;
       DWORD dwSize     = _MAX_PATH + 1;
       LPTSTR pszAppDir = new TCHAR[dwSize];
    
       if( ::GetModuleFileName( NULL, pszAppDir, dwSize ) )
       {
          strAppDir = pszAppDir;
          int nPos = strAppDir.ReverseFind( _T('\\') );
          if( -1 != nPos )
          {
             strAppDir = strAppDir.Left( nPos );
             bRet = true;
          }
       }
       delete []pszAppDir;
    
       return bRet;
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured