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".
This commit is contained in:
Jonathan Li 2015-12-22 23:20:30 +00:00
parent e34b509b20
commit e5535ccc8f
1 changed files with 8 additions and 1 deletions

View File

@ -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