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>
This commit is contained in:
parent
038c57f4b3
commit
27e94bd9d1
@ -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
|
||||
*****************************************************************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user