1,
char FileName[1024];GetCurrentDirectory(1024,FileName);
CString AppPath =FileName;
2,
HMODULE hModule=(HMODULE)AfxGetApp()->m_hInstance;
char lpFn[100];
// HANDLE hFile;
::GetModuleFileName(hModule,lpFn,100);
3,
char szFilename[MAX_PATH];
DWORD dwPathLen = 0;
if((dwPathLen = ::GetModuleFileName(
::AfxGetInstanceHandle(),
szFilename,
MAX_PATH
)) == 0) {
return FALSE;
}
for(int i=dwPathLen-1; i>=0; i--) {
if(('//' == szFilename[i])
|| ('/' == szFilename[i])) {
break;
} else {
szFilename[i] = '/0';
}
}
AfxMessageBox(szFilename);
4,
CString GetAppPath()
{
CString m_sCPath,str ;
char dir[300] ;
HINSTANCE hpin= AfxGetInstanceHandle() ;
GetModuleFileName(hpin,dir,299);
m_sCPath = dir ;//当前路径
str = AfxGetApp()->m_pszExeName;
str = str+".exe" ;
m_sCPath.MakeLower() ;
str.MakeLower() ;
int ipos ;
ipos = m_sCPath.Find(str ) ;
m_sCPath.Delete(ipos ,str.GetLength()) ;
if ( m_sCPath.Right(1)!='//')
{
m_sCPath = m_sCPath+"//" ;
}
return m_sCPath ;
}