方法一:GetModuleFileName
CString stmp = "";
TCHAR exeFullPath[_MAX_PATH];
GetModuleFileName(NULL, exeFullPath, _MAX_PATH);
stmp = exeFullPath;
int n = stmp.ReverseFind('\\');
stmp = stmp.Mid(0, n);
strcpy(exeFullPath, stmp);
SetCurrentDirectory((LPTSTR)exeFullPath);
CString filedir = exeFullPath;
方法二:GetCurrentDirectory
CString strCurrentDir;
char cBuf[MAX_PATH];
GetCurrentDirectory(MAX_PATH, cBuf);
strcat(cBuf, strCurrentDir);
strCurrentDir = cBuf;
本文介绍了两种获取程序执行路径和当前工作目录的方法。方法一是通过GetModuleFileName获取完整可执行文件路径,然后设置当前目录;方法二是利用GetCurrentDirectory直接获取当前工作目录。这些方法对于程序运行时定位资源文件至关重要。

2782

被折叠的 条评论
为什么被折叠?



