From 572db9c0a14e251d040a1ef90f7a4a8bce6ad97e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jan 2017 23:39:52 +0100 Subject: [PATCH 1/5] Extract setting WINVER/_WIN32_WINNT to a separate file This will allow reusing it from other places. --- Makefile.in | 2 ++ build/bakefiles/files.bkl | 1 + build/files | 1 + include/wx/msw/winver.h | 36 ++++++++++++++++++++++++++++++++++++ include/wx/msw/wrapwin.h | 23 ++++------------------- 5 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 include/wx/msw/winver.h diff --git a/Makefile.in b/Makefile.in index cf9010566b..aca8240492 100644 --- a/Makefile.in +++ b/Makefile.in @@ -743,6 +743,7 @@ ALL_PORTS_BASE_HEADERS = \ wx/msw/stackwalk.h \ wx/msw/stdpaths.h \ wx/msw/winundef.h \ + wx/msw/winver.h \ wx/msw/wrapcctl.h \ wx/msw/wrapcdlg.h \ wx/msw/wrapwin.h \ @@ -2581,6 +2582,7 @@ COND_PLATFORM_WIN32_1_BASE_PLATFORM_HDR = \ wx/msw/stackwalk.h \ wx/msw/stdpaths.h \ wx/msw/winundef.h \ + wx/msw/winver.h \ wx/msw/wrapcctl.h \ wx/msw/wrapcdlg.h \ wx/msw/wrapwin.h \ diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 609ede490d..d3ca55da79 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -169,6 +169,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/msw/stackwalk.h wx/msw/stdpaths.h wx/msw/winundef.h + wx/msw/winver.h wx/msw/wrapcctl.h wx/msw/wrapcdlg.h wx/msw/wrapwin.h diff --git a/build/files b/build/files index af994ad48a..2473d9dc50 100644 --- a/build/files +++ b/build/files @@ -124,6 +124,7 @@ BASE_WIN32_HDR = wx/msw/stackwalk.h wx/msw/stdpaths.h wx/msw/winundef.h + wx/msw/winver.h wx/msw/wrapcctl.h wx/msw/wrapcdlg.h wx/msw/wrapwin.h diff --git a/include/wx/msw/winver.h b/include/wx/msw/winver.h new file mode 100644 index 0000000000..90ee7bf46c --- /dev/null +++ b/include/wx/msw/winver.h @@ -0,0 +1,36 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/msw/winver.h +// Purpose: Define Windows version macros if they're not predefined. +// Author: Vadim Zeitlin +// Created: 2017-01-13 (extracted from wx/msw/wrapwin.h) +// Copyright: (c) 2017 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_WINVER_H_ +#define _WX_MSW_WINVER_H_ + +// Notice that this header must not include any other wx headers as it's +// indirectly included from wx/defs.h itself when using gcc (via wx/platform.h, +// then wx/compiler.h and wx/msw/gccpriv.h). + +// Define WINVER, _WIN32_WINNT and _WIN32_IE to the highest possible values +// because we always check for the version of installed DLLs at runtime anyway +// (see wxGetWinVersion() and wxApp::GetComCtl32Version()) unless the user +// really doesn't want to use APIs only available on later OS versions and had +// defined them to (presumably lower) values -- or, alternatively, wants to use +// even higher version of the API which will become available later. + +#ifndef WINVER + #define WINVER 0x0603 +#endif + +#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0603 +#endif + +#ifndef _WIN32_IE + #define _WIN32_IE 0x0700 +#endif + +#endif // _WX_MSW_WINVER_H_ diff --git a/include/wx/msw/wrapwin.h b/include/wx/msw/wrapwin.h index eb94226059..1bbe4f4143 100644 --- a/include/wx/msw/wrapwin.h +++ b/include/wx/msw/wrapwin.h @@ -12,6 +12,10 @@ #include "wx/platform.h" +// before including windows.h, define version macros at (currently) maximal +// values because we do all our checks at run-time anyhow +#include "wx/msw/winver.h" + // strict type checking to detect conversion from HFOO to HBAR at compile-time #ifndef STRICT #define STRICT 1 @@ -24,25 +28,6 @@ #endif // NOMINMAX -// before including windows.h, define version macros at (currently) maximal -// values because we do all our checks at run-time anyhow -#ifndef WINVER - #define WINVER 0x0603 -#endif - -// define _WIN32_WINNT and _WIN32_IE to the highest possible values because we -// always check for the version of installed DLLs at runtime anyway (see -// wxGetWinVersion() and wxApp::GetComCtl32Version()) unless the user really -// doesn't want to use APIs only available on later OS versions and had defined -// them to (presumably lower) values -#ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0603 -#endif - -#ifndef _WIN32_IE - #define _WIN32_IE 0x0700 -#endif - // For IPv6 support, we must include winsock2.h before winsock.h, and // windows.h include winsock.h so do it before including it #if wxUSE_IPV6 From 7477e94b2d456c93abb0cb65957b0e8f34a4f4a7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jan 2017 23:40:37 +0100 Subject: [PATCH 2/5] Fix build problems due to "missing" newer MSW APIs with MinGW 5.3.0 Set WINVER/_WIN32_WINNT ourselves before letting MinGW to set them to very low values corresponding to Windows 2000 on its own and preventing our code from seeing any later additions to the Windows API, such as AttachConsole() function used in src/msw/app.cpp. Closes #17677. --- include/wx/msw/gccpriv.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/wx/msw/gccpriv.h b/include/wx/msw/gccpriv.h index b12efa9b2c..45b2c758f1 100644 --- a/include/wx/msw/gccpriv.h +++ b/include/wx/msw/gccpriv.h @@ -33,6 +33,14 @@ #endif #endif + /* + MinGW 5.3.0 (and presumably later) predefines _WIN32_WINNT and WINVER + in sdkddkver.h included from _mingw.h to very low (Windows 2000!) + values. We really want to predefine them ourselves instead, so do it + before including _mingw.h. + */ + #include "wx/msw/winver.h" + #include <_mingw.h> /* From 7c22e4257b1c1bc01094ee39d45bc824f6aea239 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jan 2017 23:52:13 +0100 Subject: [PATCH 3/5] Fix build with MinGW 5.3 in debug mode Due to a bug in MinGW (see https://sourceforge.net/p/mingw/bugs/2322/), _stricmp() and _strnicmp() declarations are not visible when compiling without optimizations. Work around this by declaring them ourselves. See #17762. --- include/wx/msw/gccpriv.h | 32 ++++++++++++++++++++------------ include/wx/platform.h | 1 + include/wx/wxcrtbase.h | 11 +++++++++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/wx/msw/gccpriv.h b/include/wx/msw/gccpriv.h index 45b2c758f1..8fd4490b73 100644 --- a/include/wx/msw/gccpriv.h +++ b/include/wx/msw/gccpriv.h @@ -149,26 +149,34 @@ the new C++11 features and not disable the use of POSIX functions, we just manually declare the functions we need in this case if necessary. */ -#if defined(__MINGW32_TOOLCHAIN__) && defined(__STRICT_ANSI__) - #define wxNEEDS_STRICT_ANSI_WORKAROUNDS - +#ifdef __MINGW32_TOOLCHAIN__ /* This macro is somewhat unusual as it takes the list of parameters inside parentheses and includes semicolon inside it as putting the semicolon outside wouldn't do the right thing when this macro is empty. */ - #define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) \ + #define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) \ extern "C" _CRTIMP rettype __cdecl __MINGW_NOTHROW func params ; - /* - There is a bug resulting in a compilation error in MinGW standard - math.h header, see https://sourceforge.net/p/mingw/bugs/2250/, work - around it here because math.h is also included from several other - standard headers (e.g. ) and we don't want to duplicate this - hack everywhere this happens. - */ - wxDECL_FOR_STRICT_MINGW32(double, _hypot, (double, double)) + #ifdef __STRICT_ANSI__ + #define wxNEEDS_STRICT_ANSI_WORKAROUNDS + + #define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) \ + wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) + + /* + There is a bug resulting in a compilation error in MinGW standard + math.h header, see https://sourceforge.net/p/mingw/bugs/2250/, work + around it here because math.h is also included from several other + standard headers (e.g. ) and we don't want to duplicate this + hack everywhere this happens. + */ + wxDECL_FOR_STRICT_MINGW32(double, _hypot, (double, double)) + #else + #define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) + #endif #else + #define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) #define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) #endif diff --git a/include/wx/platform.h b/include/wx/platform.h index b490d52a96..122ffabef4 100644 --- a/include/wx/platform.h +++ b/include/wx/platform.h @@ -358,6 +358,7 @@ # define wxCHECK_W32API_VERSION(maj, min) (0) # undef wxCHECK_MINGW32_VERSION # define wxCHECK_MINGW32_VERSION( major, minor ) (0) +# define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) # define wxDECL_FOR_STRICT_MINGW32(rettype, func, params) #endif diff --git a/include/wx/wxcrtbase.h b/include/wx/wxcrtbase.h index 9b84d737bd..77c93c8e0b 100644 --- a/include/wx/wxcrtbase.h +++ b/include/wx/wxcrtbase.h @@ -230,8 +230,15 @@ extern unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int #define wxCRT_StricmpA stricmp #define wxCRT_StrnicmpA strnicmp #elif defined(__VISUALC__) || defined(__MINGW32__) - wxDECL_FOR_STRICT_MINGW32(int, _stricmp, (const char*, const char*)) - wxDECL_FOR_STRICT_MINGW32(int, _strnicmp, (const char*, const char*, size_t)) + /* + Due to MinGW 5.3 bug (https://sourceforge.net/p/mingw/bugs/2322/), + _stricmp() and _strnicmp() are not declared in its standard headers + when compiling without optimizations. Work around this by always + declaring them ourselves (notice that if/when this bug were fixed, we'd + still need to use wxDECL_FOR_STRICT_MINGW32() for them here. + */ + wxDECL_FOR_MINGW32_ALWAYS(int, _stricmp, (const char*, const char*)) + wxDECL_FOR_MINGW32_ALWAYS(int, _strnicmp, (const char*, const char*, size_t)) #define wxCRT_StricmpA _stricmp #define wxCRT_StrnicmpA _strnicmp From 22406c7d862c1a5e48d32d711a4488669596f7e2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Jan 2017 00:07:44 +0100 Subject: [PATCH 4/5] Fix configure build with MinGW 5.3.0 Provide our own wcsnlen() declaration as the function is detected by configure but is not declared in MinGW headers. Closes #17762. --- include/wx/wxcrtbase.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/wx/wxcrtbase.h b/include/wx/wxcrtbase.h index 77c93c8e0b..7391bc5283 100644 --- a/include/wx/wxcrtbase.h +++ b/include/wx/wxcrtbase.h @@ -221,6 +221,13 @@ extern unsigned long android_wcstoul(const wchar_t *nptr, wchar_t **endptr, int #endif #ifdef HAVE_WCSNLEN + /* + When using MinGW, wcsnlen() is not declared, but is still found by + configure -- just declare it in this case as it seems better to use it + if it's available (see https://sourceforge.net/p/mingw/bugs/2332/) + */ + wxDECL_FOR_MINGW32_ALWAYS(size_t, wcsnlen, (const wchar_t*, size_t)) + #define wxCRT_StrnlenW wcsnlen #endif From 6c827301d1aa34af16f035d1ec160162bde2da11 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Jan 2017 01:16:51 +0100 Subject: [PATCH 5/5] Fix regex library compilation after MinGW _stricmp() fixes Don't use extern "C" in C code. --- include/wx/msw/gccpriv.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/gccpriv.h b/include/wx/msw/gccpriv.h index 8fd4490b73..319b98746b 100644 --- a/include/wx/msw/gccpriv.h +++ b/include/wx/msw/gccpriv.h @@ -150,13 +150,23 @@ manually declare the functions we need in this case if necessary. */ #ifdef __MINGW32_TOOLCHAIN__ + /* + The macro below is used in wx/wxcrtbase.h included from C regex library + code, so make sure it compiles in non-C++ code too. + */ + #ifdef __cplusplus + #define wxEXTERNC extern "C" + #else + #define wxEXTERNC + #endif + /* This macro is somewhat unusual as it takes the list of parameters inside parentheses and includes semicolon inside it as putting the semicolon outside wouldn't do the right thing when this macro is empty. */ #define wxDECL_FOR_MINGW32_ALWAYS(rettype, func, params) \ - extern "C" _CRTIMP rettype __cdecl __MINGW_NOTHROW func params ; + wxEXTERNC _CRTIMP rettype __cdecl __MINGW_NOTHROW func params ; #ifdef __STRICT_ANSI__ #define wxNEEDS_STRICT_ANSI_WORKAROUNDS