Skip to content

Commit

Permalink
Use GetTempPath2W whenever available (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankamat-msft authored Dec 11, 2024
1 parent 7ebf7a0 commit 0a4edad
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ namespace MAT_NS_BEGIN {
std::string GetTempDirectory()
{
#ifdef _WIN32
auto lpGetTempPathW = reinterpret_cast<decltype(&::GetTempPathW)>(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);
}
Expand Down

0 comments on commit 0a4edad

Please sign in to comment.