Skip to content

Commit

Permalink
Fix compilation with MinGW on Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shoogle authored and igorkorsukov committed Mar 19, 2021
1 parent ac413b2 commit e0eaf97
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
3 changes: 3 additions & 0 deletions build/cmake/SetupBuildEnvironment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
11 changes: 1 addition & 10 deletions src/libmscore/scorefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LPCWSTR>(backupDirNativePath.utf16()), FILE_ATTRIBUTE_HIDDEN);
#endif
}
const QString backupName = QString(".") + info.fileName() + QString(",");
Expand Down

0 comments on commit e0eaf97

Please sign in to comment.