#include <iostream>
//参数,需要拼接的字符,返回路径不带\
std::string GetCurrentExecutablePath(const char* _addStr = nullptr) {
char buffer[MAX_PATH];
// 获取当前执行文件路径
HMODULE hModule = GetModuleHandle(NULL);
if (hModule != NULL) {
GetModuleFileNameA(hModule, buffer, MAX_PATH);
}
// 获取目录部分
std::string executablePath(buffer);
size_t pos = executablePath.find_last_of("\\/");
executablePath = (pos != std::string::npos) ? executablePath.substr(0, pos) : "";
if (_addStr) {
executablePath += _addStr;
}
return executablePath;
}
评论 0
友善交流,让讨论变得更有价值。