[C++] WinApi : How to get the current exe program Path
#include <Windows.h>
TCHAR szFilePath[1024];
GetModuleFileName(m_hInstance, szFilePath, 1024);
CString sPath(szFilePath);
int pos = sPath.ReverseFind('\\');
if (pos >= 0)
{
sPath = sPath.Left(pos+1);
}
-----------------------
TCHAR fullPath[MAX_PATH];
TCHAR driveLetter[3];
TCHAR directory[MAX_PATH];
TCHAR FinalPath[MAX_PATH];
GetModuleFileName(NULL, fullPath, MAX_PATH);
_splitpath(fullPath, driveLetter, directory, NULL, NULL);
sprintf(FinalPath, "%s%s",driveLetter, directory);