第一种方案:
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:\**\**\
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;
}