diff options
| author | Léo Lam <leo@leolam.fr> | 2019-11-09 21:10:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-09 21:10:16 +0100 |
| commit | f4e12f85bce7f0ad3c3fcc5d19d7db495600a41b (patch) | |
| tree | 5960897f371699d1b107c4c7007d541fb8694d79 /Source/Core/Common/CommonFuncs.cpp | |
| parent | 6cb60f8d364fc9887bfb4779993036d5554902a2 (diff) | |
| parent | ea8a3059bff1693ea640777a3aeb0c31daf18951 (diff) | |
Merge pull request #8393 from CookiePLMonster/long-paths
Support Windows 10 long paths
Diffstat (limited to 'Source/Core/Common/CommonFuncs.cpp')
| -rw-r--r-- | Source/Core/Common/CommonFuncs.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Source/Core/Common/CommonFuncs.cpp b/Source/Core/Common/CommonFuncs.cpp index 7b109e81c5..a8c1abfea2 100644 --- a/Source/Core/Common/CommonFuncs.cpp +++ b/Source/Core/Common/CommonFuncs.cpp @@ -49,4 +49,27 @@ std::string GetLastErrorString() MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_message, BUFFER_SIZE, nullptr); return std::string(error_message); } + +// Obtains a full path to the specified module. +std::optional<std::wstring> GetModuleName(void* hInstance) +{ + DWORD max_size = 50; // Start with space for 50 characters and grow if needed + std::wstring name(max_size, L'\0'); + + DWORD size; + while ((size = GetModuleFileNameW(static_cast<HMODULE>(hInstance), name.data(), max_size)) == + max_size && + GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + max_size *= 2; + name.resize(max_size); + } + + if (size == 0) + { + return std::nullopt; + } + name.resize(size); + return name; +} #endif |
