Skip to content

Commit 0a4edad

Browse files
authored
Use GetTempPath2W whenever available (#1317)
1 parent 7ebf7a0 commit 0a4edad

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/utils/Utils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ namespace MAT_NS_BEGIN {
125125
std::string GetTempDirectory()
126126
{
127127
#ifdef _WIN32
128+
auto lpGetTempPathW = reinterpret_cast<decltype(&::GetTempPathW)>(GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetTempPath2W"));
129+
if (lpGetTempPathW == NULL)
130+
{
131+
lpGetTempPathW = ::GetTempPathW;
132+
}
128133
/* UTF-8 temp directory for Win32 Desktop apps */
129134
std::string path = "";
130135
wchar_t lpTempPathBuffer[MAX_PATH + 1] = { 0 };
131-
if (::GetTempPathW(MAX_PATH, lpTempPathBuffer))
136+
if (lpGetTempPathW(MAX_PATH, lpTempPathBuffer))
132137
{
133138
path = to_utf8_string(lpTempPathBuffer);
134139
}

0 commit comments

Comments
 (0)