获取MFC中EXE的路径名

inline CString GetAppPath()
{
HMODULE hModule = GetModuleHandle(NULL);
ASSERT(hModule);

TCHAR tcPath[_MAX_PATH];
ZeroMemory(tcPath, sizeof(TCHAR) * _MAX_PATH);
DWORD dwRet = GetModuleFileName(hModule, tcPath, _MAX_PATH);

if(dwRet == 0)
return _T("");

CString strAppPath = tcPath;
int pos = strAppPath.ReverseFind(_T('\\'));
ASSERT(pos != -1);

int length = strAppPath.GetLength();
strAppPath.Delete(pos+1, length-(pos+1));

return strAppPath;
}

posted @ 2013-11-30 13:59  高_山_流_水  阅读(233)  评论(0)    收藏  举报