VS2010/MFC 获取当前程序路径 CString类型

来源:互联网 发布:如何加入淘宝外卖 编辑:程序博客网 时间:2024/06/04 22:46
第一种方案:
TCHAR szFilePath[MAX_PATH + 1]={0};
GetModuleFileName(NULL, szFilePath, MAX_PATH);                            // C:\**\**\Test.exe
(_tcsrchr(szFilePath, _T('\\')))[1] = 0; // 删除文件名,只获得路径字串   // C:\**\**\
CString str_url = szFilePath;                                                                        // C:\**\**\

CString strBookPath = str_url+ L"test.xls";






第二种方案:
CString GetAppPath()
{
char szPath[MAX_PATH];
GetModuleFileName(NULL, szPath, MAX_PATH);
CString strPath = szPath;
int nPos = strPath.ReverseFind('\\');
int nLen = strPath.GetLength();
if(nPos > 0)
strPath = strPath.Left(nPos);
return strPath;
}

0 0