-
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.
-
-
Use GetCurrentDirectory API
-
As the first reply mentioned, use GetModuleFileName().
It is explained in the FAQ at :
http://www.codeguru.com/forum/showth...hreadid=231171
-
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.
-
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;
}