From e5535ccc8f234ef7b7f3c61c3918953857d3f071 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Tue, 22 Dec 2015 23:20:30 +0000 Subject: [PATCH] 3rdparty:wxwidgets: Preserve Win32 last error in wxTlsKey::Get() This is commit e093a3b1b402c067254558d24ef2d7f39f552251 from the wx3.0 stable branch. The correct error code and message is now output when an error takes place. Previously it would report an error code of 0 and inform us that "The operation completed successfully". --- 3rdparty/wxwidgets3.0/include/wx/msw/tls.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/3rdparty/wxwidgets3.0/include/wx/msw/tls.h b/3rdparty/wxwidgets3.0/include/wx/msw/tls.h index 9d46cadf3e..962490858d 100644 --- a/3rdparty/wxwidgets3.0/include/wx/msw/tls.h +++ b/3rdparty/wxwidgets3.0/include/wx/msw/tls.h @@ -34,7 +34,14 @@ public: // get the key value, there is no error return void *Get() const { - return ::TlsGetValue(m_slot); + // Exceptionally, TlsGetValue() calls SetLastError() even on success + // which means it overwrites the previous value. This is undesirable + // here, so explicitly preserve the last error here. + const DWORD dwLastError = ::GetLastError(); + void* const value = ::TlsGetValue(m_slot); + if (dwLastError) + ::SetLastError(dwLastError); + return value; } // change the key value, return true if ok