|
-
March 19th, 2003, 08:39 AM
#1
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.
-
March 19th, 2003, 08:43 AM
#2
-
March 19th, 2003, 10:47 AM
#3
Use GetCurrentDirectory API
-
March 19th, 2003, 11:09 AM
#4
As the first reply mentioned, use GetModuleFileName().
It is explained in the FAQ at :
http://www.codeguru.com/forum/showth...hreadid=231171
-
March 19th, 2003, 11:14 AM
#5
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.
-
March 19th, 2003, 11:27 AM
#6
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;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|