From e99992b42d6b30a457d0303626c86fad3f95e28f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 9 Dec 2020 14:57:21 +0100 Subject: [PATCH] Fix crash when using list or tree control in ANSI build of wxMSW Calling SystemParametersInfoForDpi() with LOGFONTA parameter corrupted the stack because this function only accepts LOGFONTW, i.e. it wrote twice as much data into the provided buffer as the caller expected. This could be fixed by allocating a temporary wide buffer and converting back, but this doesn't seem to be worth it, so just disable the use of the DPI-specific function in the ANSI build. Closes #19002. --- src/msw/window.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 9e7e26a778..c233df3354 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4807,7 +4807,12 @@ int wxGetSystemMetrics(int nIndex, const wxWindow* win) /*extern*/ bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, const wxWindow* win) { -#if wxUSE_DYNLIB_CLASS + // Note that we can't use SystemParametersInfoForDpi() in non-Unicode build + // because it always works with wide strings and we'd have to check for all + // uiAction values corresponding to strings and use a temporary wide buffer + // for them, and convert the returned value to ANSI after the call. Instead + // of doing all this, just don't use it at all in the deprecated ANSI build. +#if wxUSE_DYNLIB_CLASS && wxUSE_UNICODE const wxWindow* window = (!win && wxTheApp) ? wxTheApp->GetTopWindow() : win; if ( window )