C++ Code Sample: Get Path of Module
Code C++ Sample. Get Path of Module Application.
Cách để lấy đường dẫn của file exe khi build trong một project phần mềm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
std::string GetModulePathExe() { std::string exePath; TCHAR chPath[MAX_PATH]; HMODULE hModule = GetModuleHandle(NULL); if (hModule != NULL) { GetModuleFileName(hModule, chPath, (sizeof(chPath))); std::wstring sTemp(&chPath[0]); //convert to wstring exePath = std::string(sTemp.begin(), sTemp.end()); exePath = exePath.substr(0, exePath.find_last_of("\\/")); } return exePath; } |