From fde3497ffe89b16cc0f78464e8272fa6e34736bd Mon Sep 17 00:00:00 2001 From: Angad Kamat Date: Mon, 9 Dec 2024 21:52:37 -0800 Subject: [PATCH] Use GetTempPath2W whenever available --- lib/utils/Utils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/utils/Utils.cpp b/lib/utils/Utils.cpp index e053526d0..eb70afdb3 100644 --- a/lib/utils/Utils.cpp +++ b/lib/utils/Utils.cpp @@ -125,10 +125,15 @@ namespace MAT_NS_BEGIN { std::string GetTempDirectory() { #ifdef _WIN32 + auto lpGetTempPathW = reinterpret_cast(GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetTempPath2W")); + if (lpGetTempPathW == NULL) + { + lpGetTempPathW = ::GetTempPathW; + } /* UTF-8 temp directory for Win32 Desktop apps */ std::string path = ""; wchar_t lpTempPathBuffer[MAX_PATH + 1] = { 0 }; - if (::GetTempPathW(MAX_PATH, lpTempPathBuffer)) + if (lpGetTempPathW(MAX_PATH, lpTempPathBuffer)) { path = to_utf8_string(lpTempPathBuffer); }