Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation with MinGW on Windows #7744

Merged
merged 1 commit into from
Mar 19, 2021

Conversation

shoogle
Copy link
Contributor

@shoogle shoogle commented Mar 18, 2021

Errors fixed:

src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp: In member function 'void mu::ui::WindowsPlatformTheme::startListening()':
src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp:78:62: error: cannot convert 'const wchar_t' to 'LPCSTR' {aka 'const char'}
     if (RegOpenKeyEx(HKEY_CURRENT_USER, windowsThemeKey.c_str(), 0,
                                                              ^
src/libmscore/scorefile.cpp: In member function 'bool Ms::MasterScore::saveFile(bool)':
src/libmscore/scorefile.cpp:460:72: error: invalid cast from type 'QByteArray' to type 'LPCTSTR' {aka 'const wchar_t*'}
             SetFileAttributes((LPCTSTR)backupDirNativePath.toLocal8Bit(), FILE_ATTRIBUTE_HIDDEN);
                                                                        ^

Edit: The errors arose because we were using these aliases from the Windows API:

  • SetFileAttributes
  • LPCTSTR

When UNICODE is defined these aliases point to 'W' (wide) symbols that provide Unicode support (UTF-16):

  • SetFileAttributesW
  • LPCWSTR

However, if UNICODE is not defined then the aliases point to the narrow ANSI (8-bit) symbols:

  • SetFileAttributesA
  • LPCSTR

The fix is to explicitly use the wide symbols (i.e. don't use the aliases). The wide symbols are available on Windows even when UNICODE is undefined; it's just the aliases that are different. The aliases are only needed for compatibility with code written prior to Windows NT, so it's probably best to avoid them.

@Jojo-Schmitz
Copy link
Contributor

Jojo-Schmitz commented Mar 18, 2021

Does it also solve the warning?

src/framework/ui/internal/platform/windows/windowsplatformtheme.cpp:41:126: warning: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'fnRtlGetNtVersionNumbers' {aka 'void (__attribute__((stdcall)) *)(long unsigned int*, long unsigned int*, long unsigned int*)'} [-Wcast-function-type]
     = reinterpret_cast<fnRtlGetNtVersionNumbers>(GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetNtVersionNumbers"));

Edit: no it does not. Not the scope of this PR I guess.

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 18, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 18, 2021
src/libmscore/scorefile.cpp Outdated Show resolved Hide resolved
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 19, 2021
@shoogle shoogle force-pushed the compile-mingw branch 2 times, most recently from 8743edd to 6cf6125 Compare March 19, 2021 14:05
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.
@igorkorsukov igorkorsukov merged commit e0eaf97 into musescore:master Mar 19, 2021
@shoogle shoogle deleted the compile-mingw branch March 19, 2021 17:56
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 20, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 24, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 24, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Apr 10, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Apr 26, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Apr 26, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request May 11, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jun 28, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jul 1, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jul 27, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jul 27, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jul 27, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jul 28, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jul 28, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 13, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 13, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 19, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Aug 19, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 2, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 10, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 23, 2021
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants