From e0eaf973ac40364d69e56474dff043445fbbbed7 Mon Sep 17 00:00:00 2001 From: Peter Jonas Date: Fri, 19 Mar 2021 14:16:00 +0000 Subject: [PATCH] Fix compilation with MinGW on Windows Use the explicit 'W' (wide) symbols from the Windows API to provide Unicode support regardless of whether UNICODE is defined: - SetFileAttributesW - LPCWSTR Define UNICODE anyway for the sake of thirdparty code that uses the aliases, which only work properly when UNICODE is defined: - SetFileAttributes - LPCTSTR If UNICODE is not defined then the aliases refer to the narrow symbols: - SetFileAttributesA - LPCSTR But the explict 'W' symbols are still available. The aliases are only needed for compatibility with code written prior to Windows NT. --- build/cmake/SetupBuildEnvironment.cmake | 3 +++ .../platform/windows/windowsplatformtheme.cpp | 6 +++--- src/libmscore/scorefile.cpp | 11 +---------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/build/cmake/SetupBuildEnvironment.cmake b/build/cmake/SetupBuildEnvironment.cmake index 1255ee2367aaa..82116a7345678 100644 --- a/build/cmake/SetupBuildEnvironment.cmake +++ b/build/cmake/SetupBuildEnvironment.cmake @@ -53,6 +53,9 @@ elseif(CC_IS_MINGW) set(CMAKE_EXE_LINKER_FLAGS "-Wl,--large-address-aware") endif (NOT BUILD_64) + add_definitions(-D_UNICODE) + add_definitions(-DUNICODE) + elseif(CC_IS_CLANG) message(STATUS "Using Compiler CLANG ${CMAKE_CXX_COMPILER_VERSION}") diff --git a/src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp b/src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp index 1798298483da3..1a57ea9c1eca0 100644 --- a/src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp +++ b/src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp @@ -75,9 +75,9 @@ void WindowsPlatformTheme::startListening() return; } m_isListening = true; - if (RegOpenKeyEx(HKEY_CURRENT_USER, windowsThemeKey.c_str(), 0, - KEY_NOTIFY | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_64KEY, - &hKey) == ERROR_SUCCESS) { + if (RegOpenKeyExW(HKEY_CURRENT_USER, windowsThemeKey.c_str(), 0, + KEY_NOTIFY | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_64KEY, + &hKey) == ERROR_SUCCESS) { m_listenThread = std::thread([this]() { th_listen(); }); } else { LOGD() << "Failed opening key for listening dark theme changes."; diff --git a/src/libmscore/scorefile.cpp b/src/libmscore/scorefile.cpp index 5e3310794a60f..e062231190de8 100644 --- a/src/libmscore/scorefile.cpp +++ b/src/libmscore/scorefile.cpp @@ -449,16 +449,7 @@ bool MasterScore::saveFile(bool generateBackup) dir.mkdir(backupSubdirString); #ifdef Q_OS_WIN const QString backupDirNativePath = QDir::toNativeSeparators(backupDirString); -#if (defined (_MSCVER) || defined (_MSC_VER)) - #if (defined (UNICODE)) - SetFileAttributes((LPCTSTR)backupDirNativePath.unicode(), FILE_ATTRIBUTE_HIDDEN); - #else - // Use byte-based Windows function - SetFileAttributes((LPCTSTR)backupDirNativePath.toLocal8Bit(), FILE_ATTRIBUTE_HIDDEN); - #endif -#else - SetFileAttributes((LPCTSTR)backupDirNativePath.toLocal8Bit(), FILE_ATTRIBUTE_HIDDEN); -#endif + SetFileAttributesW(reinterpret_cast(backupDirNativePath.utf16()), FILE_ATTRIBUTE_HIDDEN); #endif } const QString backupName = QString(".") + info.fileName() + QString(",");