Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guy
I'm have a MFC application, and there doc is *.cvt
When I double click cvt file, GetCurrentDir function is get path of cvt file, not path of application file
How i get path Application file ?

C++
CString utility::GetPathExe()
{
	char cCurrentPath[FILENAME_MAX];
	if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
	{
		return _T("");
	}
	cCurrentPath[sizeof(cCurrentPath)-1] = '\0'; /* not really required */
	CString szResult = _T("");
	szResult = cCurrentPath;
	return szResult;
}
Posted

1 solution

The path and name of the executable file are stored in the first command line argument array entry that is passed to the main function. So you may copy that or store a pointer.

Alternatively you can use the GetModuleFileName()[^] function:
// Get path of the executable file of the current process
TCHAR path[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
// Remove the file name
// Set ext[0] to zero to strip also the trailing back slash
LPCTSTR ext = _tcsrchr(path, _T('\\'));
if (ext)
    ext[1] = _T('\0');
 
Share this answer
 
Comments
Mạnh Lê 16-Dec-15 3:59am    
thank your recommend.
I'm using GetModuleFileName is successfully
.
TCHAR path[FILENAME_MAX];
GetModuleFileName(NULL, path, FILENAME_MAX);
// Remove the file name
CString s = path;
CString szResult = s.Left(s.ReverseFind('\\') + 1);
return szResult;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900