- 1. 获取Debug或Release所在的路径
- CString GetModuleDir()
- {
- HMODULE module = GetModuleHandle(0);
- char pFileName[MAX_PATH];
- GetModuleFileName(module, pFileName, MAX_PATH);
- CString csFullPath(pFileName);
- int nPos = csFullPath.ReverseFind( _T('\\') );
- if( nPos < 0 )
- return CString("");
- else
- return csFullPath.Left( nPos );
- }
- 2. 获取当前工作路径(dsp所在路径)
- //获取工作路径
- CString GetWorkDir()
- {
- char pFileName[MAX_PATH];
- int nPos = GetCurrentDirectory( MAX_PATH, pFileName);
- CString csFullPath(pFileName);
- if( nPos < 0 )
- return CString("");
- else
- return csFullPath;
- }
路径分解函数:
[cpp] view plain copy- char a_sFileName[256];
- GetModuleFileName(NULL,a_sFileName,256);
- CString sPath;
- CString sDrive;//磁盘名
- CString sDir;//文件路径
- CString sFileName;//取出文件路径后的文件名
- CString sExt;//文件扩展名
- char drive[_MAX_DRIVE];//磁盘名
- char dir[_MAX_DIR];//路径名
- char fname[_MAX_FNAME];//文件名
- char ext[_MAX_EXT];//扩展名
- _splitpath(a_sFileName, drive, dir, fname, ext );
- sDrive.Format("%s",drive);
- sDir.Format("%s",dir);
- sFileName.Format("%s",fname);
- sExt.Format("%s",ext);
- sPath= sDrive + sDir + sFileName + a_sSuffix + sExt;