Visual C++获取程序当前路径

CString CPropertySampleApp::GetCurrWorkingDir()
{
  CString strPath;
  TCHAR szFull[_MAX_PATH];
  TCHAR szDrive[_MAX_DRIVE];
  TCHAR szDir[_MAX_DIR];
  ::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
  _tsplitpath(szFull, szDrive, szDir, NULL, NULL);
  _tcscpy(szFull, szDrive);
  _tcscat(szFull, szDir);
  strPath = CString(szFull);
  return strPath;
}

 

  CString strPath;
  GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
  strPath.ReleaseBuffer();
  int pos = strPath.ReverseFind('\\');
  strPath = strPath.Left(pos+1);

 

posted @ 2013-11-25 11:06  曦花  阅读(255)  评论(0)    收藏  举报