From b195cbbcd0dd9839b4e15a39f3e78178ed684c23 Mon Sep 17 00:00:00 2001 From: Carlo Bramini <30959007+carlo-bramini@users.noreply.github.com> Date: Sun, 1 May 2022 18:45:54 +0200 Subject: [PATCH] WIN32: Migrate from ShellExecute to ShellExecuteEx Function That function allows more readable code, without needing to test if the returned value is greater than 32. Supported platforms are: Windows 95: Supported. Windows 98: Supported. Windows NT: Required Windows NT 4.0 or later. Windows 2000 and newer: Supported. Windows CE: Requires Windows CE 1.0 or later. This fix comes from my port of SCUMMVM for Windows CE/Embedded/Mobile since this family of OSs support ShellExecuteEx(), but not ShellExecute(). --- backends/platform/sdl/win32/win32.cpp | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index fe3f6f4cc37..3df2d243c01 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -159,8 +159,15 @@ bool OSystem_Win32::displayLogFile() { // Try opening the log file with the default text editor // log files should be registered as "txtfile" by default and thus open in the default text editor TCHAR *tLogFilePath = Win32::stringToTchar(_logFilePath); - HINSTANCE shellExec = ShellExecute(getHwnd(), nullptr, tLogFilePath, nullptr, nullptr, SW_SHOWNORMAL); - if ((intptr_t)shellExec > 32) { + SHELLEXECUTEINFO sei; + + memset(&sei, 0, sizeof(sei)); + sei.fMask = SEE_MASK_FLAG_NO_UI; + sei.hwnd = getHwnd(); + sei.lpFile = tLogFilePath; + sei.nShow = SW_SHOWNORMAL; + + if (ShellExecuteEx(&sei)) { free(tLogFilePath); return true; } @@ -196,11 +203,20 @@ bool OSystem_Win32::displayLogFile() { bool OSystem_Win32::openUrl(const Common::String &url) { TCHAR *tUrl = Win32::stringToTchar(url); - HINSTANCE result = ShellExecute(getHwnd(), nullptr, tUrl, nullptr, nullptr, SW_SHOWNORMAL); + SHELLEXECUTEINFO sei; + + memset(&sei, 0, sizeof(sei)); + sei.cbSize = sizeof(sei); + sei.fMask = SEE_MASK_FLAG_NO_UI; + sei.hwnd = getHwnd(); + sei.lpFile = tUrl; + sei.nShow = SW_SHOWNORMAL; + + BOOL success = ShellExecuteEx(&sei); + free(tUrl); - // ShellExecute returns a value greater than 32 if successful - if ((intptr_t)result <= 32) { - warning("ShellExecute failed: error = %p", (void*)result); + if (!success) { + warning("ShellExecuteEx failed: error = %08lX", GetLastError()); return false; } return true;