| 22 | } |
| 23 | |
| 24 | std::filesystem::path ModuleFilePath(HMODULE module, const char* operation) { |
| 25 | for (DWORD capacity = MAX_PATH; capacity <= kMaxWin32PathBuffer; capacity *= 2) { |
| 26 | std::vector<wchar_t> buffer(capacity); |
| 27 | SetLastError(ERROR_SUCCESS); |
| 28 | const DWORD len = GetModuleFileNameW(module, buffer.data(), capacity); |
| 29 | if (len == 0) { |
| 30 | OSTP_LOG_WARN("{}: GetModuleFileNameW failed (error={})", operation, GetLastError()); |
| 31 | return {}; |
| 32 | } |
| 33 | if (len < capacity) { |
| 34 | return std::filesystem::path(std::wstring_view(buffer.data(), len)); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | OSTP_LOG_WARN("{}: GetModuleFileNameW path exceeds {} wchars", operation, kMaxWin32PathBuffer); |
| 39 | return {}; |
| 40 | } |
| 41 | |
| 42 | std::string DirectoryFromQuery(DWORD (*query)(DWORD, wchar_t*), const char* operation) { |
| 43 | for (DWORD capacity = MAX_PATH; capacity <= kMaxWin32PathBuffer; capacity *= 2) { |
no test coverage detected