1.取得当前目录
char szModulePath [_MAX_PATH]; /* Path of Module */ // Get current module handle HMODULE module = GetModuleHandle(0); // Get current file path GetModuleFileName(module, szModulePath, sizeof(szModulePath)); CString strPath = szModulePath; strPath = strPath.Left(strPath.ReverseFind(_T('//'))); lstrcpy(szModulePath, strPath.GetBuffer(strPath.GetLength()));
2.取得操作系统盘符
TCHAR sysDir[128]; GetSystemDirectory(sysDir, 128 * sizeof(TCHAR)); CString sysDisk = sysDir[0]; sysDisk.MakeUpper();
本文介绍如何使用C++通过API获取当前运行模块的文件路径,并从中提取出当前目录。此外,还提供了获取操作系统的根盘符的方法。
1万+

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



