方法一:
void GetAppPath(wstring &sPath)
{
sPath.resize(MAX_PATH);
::GetModuleFileName(GetModuleHandle(NULL), (LPTSTR)sPath.c_str(), MAX_PATH);
int index = sPath.find_last_of(L'\\');
if(index >= 0) sPath = sPath.substr(0, index);
}
方法二:
CString GetCurrPath()
{
char fullpath[256] = {0};
GetModuleFileName(NULL, fullpath, MAX_PATH);
CString cspath(fullpath);
int index = cspath.ReverseFind('\\');
return cspath.Left(index);
}
方法三:
{
char lpFileName[MAX_PATH];
GetModuleFileName(NULL, lpFileName, sizeof(lpFileName));
char* p = strrchr(lpFileName, '\\');
if( p )
*p = 0;
}