summaryrefslogtreecommitdiffstats
path: root/src/winmain
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-04-30 08:46:16 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-15 09:34:19 +0200
commit9b121e5579538477a1fc7c8250e5d7e875a58de8 (patch)
tree2971eedf712f52c299fca687f97ed552e333f9ac /src/winmain
parent9dc254ad5031a1335c163f156abfd573f11a935f (diff)
Windows: Use WinAPI CommandLineToArgvW() to create argv from command line.
Split the Windows CE/Desktop Windows code paths in winmain. Use CommandLineToArgvW() to obtain argv[] for Desktop Windows. [ChangeLog][QtCore][Windows] Command line parsing on Windows now uses the WinAPI function CommandLineToArgvW() to exactly match the quoting of the command interpreter. Task-number: QTBUG-35432 Task-number: QTBUG-23687 Change-Id: I6743e73649d953497642f7717d3731a83ffda2a2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/winmain')
-rw-r--r--src/winmain/qtmain_win.cpp50
-rw-r--r--src/winmain/winmain.pro2
2 files changed, 40 insertions, 12 deletions
diff --git a/src/winmain/qtmain_win.cpp b/src/winmain/qtmain_win.cpp
index dc765ea56a..778ddee64b 100644
--- a/src/winmain/qtmain_win.cpp
+++ b/src/winmain/qtmain_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Windows main function of the Qt Toolkit.
@@ -43,6 +43,10 @@
#include "qstring.h"
#include "qvector.h"
+#ifndef Q_OS_WINCE
+# include <shlobj.h>
+#endif
+
/*
This file contains the code in the qtmain library for Windows.
qtmain contains the Windows startup code and is required for
@@ -83,26 +87,49 @@ extern "C" int main(int, char **);
application.
*/
-#ifdef Q_OS_WINCE
+#ifndef Q_OS_WINCE
+
+// Convert a wchar_t to char string, equivalent to QString::toLocal8Bit()
+// when passed CP_ACP.
+static inline char *wideToMulti(int codePage, const wchar_t *aw)
+{
+ const int required = WideCharToMultiByte(codePage, 0, aw, -1, NULL, 0, NULL, NULL);
+ char *result = new char[required];
+ WideCharToMultiByte(codePage, 0, aw, -1, result, required, NULL, NULL);
+ return result;
+}
+
+extern "C" int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR /*cmdParamarg*/, int /* cmdShow */)
+{
+ int argc;
+ wchar_t **argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
+ if (!argvW)
+ return -1;
+ char **argv = new char *[argc];
+ for (int i = 0; i < argc; ++i)
+ argv[i] = wideToMulti(CP_ACP, argvW[i]);
+ LocalFree(argvW);
+ const int exitCode = main(argc, argv);
+ for (int i = 0; i < argc; ++i)
+ delete [] argv[i];
+ delete [] argv;
+ return exitCode;
+}
+
+#else // !Q_OS_WINCE
+
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR /*wCmdParam*/, int cmdShow)
-#else
-extern "C"
-int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /*cmdParamarg*/, int cmdShow)
-#endif
{
QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit();
-#if defined(Q_OS_WINCE)
wchar_t appName[MAX_PATH];
GetModuleFileName(0, appName, MAX_PATH);
cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit());
-#endif
int argc = 0;
QVector<char *> argv(8);
qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv);
-#if defined(Q_OS_WINCE)
wchar_t uniqueAppID[MAX_PATH];
GetModuleFileName(0, uniqueAppID, MAX_PATH);
QString uid = QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1String("\\"), QLatin1String("_"));
@@ -126,11 +153,10 @@ int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /*cmdPara
SetForegroundWindow((HWND)(((ULONG)aHwnd) | 0x01));
return 0;
}
-#endif // Q_OS_WINCE
int result = main(argc, argv.data());
-#if defined(Q_OS_WINCE)
CloseHandle(mutex);
-#endif
return result;
}
+
+#endif // Q_OS_WINCE
diff --git a/src/winmain/winmain.pro b/src/winmain/winmain.pro
index 998200cb1e..284f2a2201 100644
--- a/src/winmain/winmain.pro
+++ b/src/winmain/winmain.pro
@@ -20,6 +20,8 @@ winrt {
SOURCES = qtmain_winrt.cpp
} else {
SOURCES = qtmain_win.cpp
+
+ !wince: LIBS += -lshell32
}
load(qt_installs)