From 27e94bd9d1ac5faaa8b1e4ee5d57f820675194b1 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 17 May 2016 16:35:04 +0200 Subject: winrt: Fix potential crash in QCoreApplication GetModuleFileName exists for Windows 10 and upwards, hence use the generic version from the win32 mkspec. This allows to create a QCoreApplication object with nullptr argv, as the application filename is identified via the binary itself and not via arguments. A couple of auto-tests use this method to create multiple application objects during runtime. Unfortunately we cannot apply this for msvc2013, even though MSDN states the GetModuleFileName exists, it fails to compile for Windows Phone 8.1. Change-Id: I2b8b988107487ef3785462f8ca40b0a6e0623e32 Reviewed-by: Thiago Macieira Reviewed-by: Oliver Wolff --- src/corelib/kernel/qcoreapplication_win.cpp | 59 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'src/corelib/kernel/qcoreapplication_win.cpp') diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 324b664a1a..1af1d44f2e 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -49,7 +49,10 @@ QT_BEGIN_NAMESPACE int appCmdShow = 0; -#if defined(Q_OS_WINRT) +// GetModuleFileName only exists for MSVC2015 and upwards for WinRT, meaning +// Windows 10 (Mobile). Hence take the first argument passed to the +// QCoreApplication contructor for older versions as a fallback on older platforms. +#if defined(Q_OS_WINRT) && _MSC_VER < 1900 Q_CORE_EXPORT QString qAppFileName() { @@ -61,31 +64,7 @@ QString QCoreApplicationPrivate::appName() const return QFileInfo(QCoreApplication::arguments().first()).baseName(); } -#else - -Q_CORE_EXPORT HINSTANCE qWinAppInst() // get Windows app handle -{ - return GetModuleHandle(0); -} - -Q_CORE_EXPORT HINSTANCE qWinAppPrevInst() // get Windows prev app handle -{ - return 0; -} - -Q_CORE_EXPORT int qWinAppCmdShow() // get main window show command -{ -#if defined(Q_OS_WINCE) - return appCmdShow; -#else - STARTUPINFO startupInfo; - GetStartupInfo(&startupInfo); - - return (startupInfo.dwFlags & STARTF_USESHOWWINDOW) - ? startupInfo.wShowWindow - : SW_SHOWDEFAULT; -#endif -} +#else // !(defined(Q_OS_WINRT) && _MSC_VER < 1900) Q_CORE_EXPORT QString qAppFileName() // get application file name { @@ -133,6 +112,34 @@ QString QCoreApplicationPrivate::appName() const return QFileInfo(qAppFileName()).baseName(); } +#endif // !(defined(Q_OS_WINRT) && _MSC_VER < 1900) + +#ifndef Q_OS_WINRT + +Q_CORE_EXPORT HINSTANCE qWinAppInst() // get Windows app handle +{ + return GetModuleHandle(0); +} + +Q_CORE_EXPORT HINSTANCE qWinAppPrevInst() // get Windows prev app handle +{ + return 0; +} + +Q_CORE_EXPORT int qWinAppCmdShow() // get main window show command +{ +#if defined(Q_OS_WINCE) + return appCmdShow; +#else + STARTUPINFO startupInfo; + GetStartupInfo(&startupInfo); + + return (startupInfo.dwFlags & STARTF_USESHOWWINDOW) + ? startupInfo.wShowWindow + : SW_SHOWDEFAULT; +#endif +} + /***************************************************************************** qWinMain() - Initializes Windows. Called from WinMain() in qtmain_win.cpp *****************************************************************************/ -- cgit v1.2.3