您的位置:首页 > 其它

获取当前应用程序路径

2007-06-01 19:32 369 查看
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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: