Skip to content

Commit c3ef0c1

Browse files
committed
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.
1 parent ac413b2 commit c3ef0c1

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

build/cmake/SetupBuildEnvironment.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ elseif(CC_IS_MINGW)
5353
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--large-address-aware")
5454
endif (NOT BUILD_64)
5555

56+
add_definitions(-D_UNICODE)
57+
add_definitions(-DUNICODE)
58+
5659
elseif(CC_IS_CLANG)
5760
message(STATUS "Using Compiler CLANG ${CMAKE_CXX_COMPILER_VERSION}")
5861

src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ void WindowsPlatformTheme::startListening()
7575
return;
7676
}
7777
m_isListening = true;
78-
if (RegOpenKeyEx(HKEY_CURRENT_USER, windowsThemeKey.c_str(), 0,
79-
KEY_NOTIFY | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_64KEY,
80-
&hKey) == ERROR_SUCCESS) {
78+
if (RegOpenKeyExW(HKEY_CURRENT_USER, windowsThemeKey.c_str(), 0,
79+
KEY_NOTIFY | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_64KEY,
80+
&hKey) == ERROR_SUCCESS) {
8181
m_listenThread = std::thread([this]() { th_listen(); });
8282
} else {
8383
LOGD() << "Failed opening key for listening dark theme changes.";

src/libmscore/scorefile.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,7 @@ bool MasterScore::saveFile(bool generateBackup)
449449
dir.mkdir(backupSubdirString);
450450
#ifdef Q_OS_WIN
451451
const QString backupDirNativePath = QDir::toNativeSeparators(backupDirString);
452-
#if (defined (_MSCVER) || defined (_MSC_VER))
453-
#if (defined (UNICODE))
454-
SetFileAttributes((LPCTSTR)backupDirNativePath.unicode(), FILE_ATTRIBUTE_HIDDEN);
455-
#else
456-
// Use byte-based Windows function
457-
SetFileAttributes((LPCTSTR)backupDirNativePath.toLocal8Bit(), FILE_ATTRIBUTE_HIDDEN);
458-
#endif
459-
#else
460-
SetFileAttributes((LPCTSTR)backupDirNativePath.toLocal8Bit(), FILE_ATTRIBUTE_HIDDEN);
461-
#endif
452+
SetFileAttributesW(reinterpret_cast<LPCWSTR>(backupDirNativePath.utf16()), FILE_ATTRIBUTE_HIDDEN);
462453
#endif
463454
}
464455
const QString backupName = QString(".") + info.fileName() + QString(",");

0 commit comments

Comments
 (0)