summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication_win.cpp
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@qt.io>2016-05-17 16:35:04 +0200
committerOliver Wolff <oliver.wolff@qt.io>2016-06-13 06:13:19 +0000
commit27e94bd9d1ac5faaa8b1e4ee5d57f820675194b1 (patch)
treec49f9f083e9acd11a8e86b7f4785b066429ddf64 /src/corelib/kernel/qcoreapplication_win.cpp
parent038c57f4b3aca1b35244fb9fbb0ae81c53279c6f (diff)
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 <thiago.macieira@intel.com> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication_win.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication_win.cpp59
1 files changed, 33 insertions, 26 deletions
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
*****************************************************************************/