From e1278cba7b611e6ba130ccbebcff40746e73f65a Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 16 Apr 2021 03:09:54 +0100 Subject: [PATCH] Fix SErrGet/SetLastError SErrGet/SetLastError were not propagating errors from 3rdParty/StormLib because StormLib uses native Windows functions on Windows and defines its own on Linux. Also removes storm_full.h --- Source/miniwin/miniwin.h | 2 -- Source/storm/storm.cpp | 18 ++++++++++++++---- Source/storm/storm_full.h | 9 --------- 3 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 Source/storm/storm_full.h diff --git a/Source/miniwin/miniwin.h b/Source/miniwin/miniwin.h index 17267e3bd..ec4805631 100644 --- a/Source/miniwin/miniwin.h +++ b/Source/miniwin/miniwin.h @@ -11,8 +11,6 @@ #include #include -#include "storm/storm_full.h" - namespace devilution { #ifndef MAX_PATH diff --git a/Source/storm/storm.cpp b/Source/storm/storm.cpp index 89a3855a1..3e5b9ec73 100644 --- a/Source/storm/storm.cpp +++ b/Source/storm/storm.cpp @@ -23,9 +23,19 @@ #include "utils/sdl_compat.h" #include "utils/stubs.h" -namespace devilution { +// Include Windows headers for Get/SetLastError. +#if defined(_WIN32) +// Suppress definitions of `min` and `max` macros by : +#define NOMINMAX 1 +#define WIN32_LEAN_AND_MEAN +#include +#else // !defined(_WIN32) +// On non-Windows, these are defined in 3rdParty/StormLib. +extern "C" void SetLastError(std::uint32_t dwErrCode); +extern "C" std::uint32_t GetLastError(); +#endif -uint32_t nLastError = 0; +namespace devilution { namespace { @@ -801,12 +811,12 @@ void SVidPlayEnd(HANDLE video) DWORD SErrGetLastError() { - return nLastError; + return ::GetLastError(); } void SErrSetLastError(DWORD dwErrCode) { - nLastError = dwErrCode; + ::SetLastError(dwErrCode); } bool SFileSetBasePath(const char *path) diff --git a/Source/storm/storm_full.h b/Source/storm/storm_full.h deleted file mode 100644 index d2304a6b7..000000000 --- a/Source/storm/storm_full.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace devilution { - -extern uint32_t nLastError; - -} // namespace devilution