--- src/activeqt/control/qaxservermain.cpp Ïò íîÿ 23 12:09:54 2012 +++ src/activeqt/control/qaxservermain.cpp Ïò ÿíâ 11 01:04:02 2013 @@ -40,6 +40,9 @@ #include #include +#include +#include +#include #include "qaxfactory.h" @@ -180,11 +183,27 @@ } #if defined(Q_OS_WINCE) -extern void __cdecl qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector &); +extern QStringList __cdecl qWinParseCmdLine(LPCWSTR cmdLine); #else -extern void qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector &); +extern QStringList qWinParseCmdLine(LPCWSTR cmdLine); #endif +#if defined(Q_OS_WINCE) +Q_CORE_EXPORT void __cdecl qWinBuildArgv(const QStringList& args, + QList& argvData, QVector& argv); +#else +Q_CORE_EXPORT void qWinBuildArgv(const QStringList& args, + QList& argvData, QVector& argv); +#endif + +#if defined(Q_OS_WINCE) +extern void __cdecl qWinMain(HINSTANCE instance, HINSTANCE prevInstance, + const QStringList& args, int cmdShow); +#else +extern void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, + const QStringList& args, int cmdShow); +#endif + QT_END_NAMESPACE #if defined(QT_NEEDS_QMAIN) @@ -207,64 +226,107 @@ GetModuleFileName(0, qAxModuleFilename, MAX_PATH); qAxInstance = hInstance; - QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit(); - QList cmds = cmdParam.split(' '); - QByteArray unprocessed; + LPWSTR winCommandLine = ::GetCommandLineW(); + const QStringList args = qWinParseCmdLine(winCommandLine); + +#if defined(Q_OS_WINCE) + // At Windows CE GetCommandLineW doesn't return module file name (?) + wchar_t appName[MAX_PATH]; + if (::GetModuleFileNameW(0, appName, MAX_PATH)) { + // Let the module file name be the first arg + args.prepend(QString::fromWCharArray(appName)); + } else { + // Failed to obtain module file name + args.prepend(QString()); + } +#endif - int nRet = 0; + // Internal command line options + QSet runServerOptions; + { + runServerOptions.insert(QString::fromLatin1("activex")); + runServerOptions.insert(QString::fromLatin1("embedding")); + } + const QString unregisterOption = QString::fromLatin1("unregserver"); + const QString registerOption = QString::fromLatin1("regserver"); + const QString dumpidlOption = QString::fromLatin1("dumpidl"); + const QString versionOption = QString::fromLatin1("version"); + + // Process comand line args and build unprocessedArgs + const int argc = args.size(); + QStringList unprocessedArgs; + unprocessedArgs.reserve(argc); + int nRet; bool run = true; bool runServer = false; - for (int i = 0; i < cmds.count(); ++i) { - QByteArray cmd = cmds.at(i).toLower(); - if (cmd == "-activex" || cmd == "/activex" || cmd == "-embedding" || cmd == "/embedding") { - runServer = true; - } else if (cmd == "-unregserver" || cmd == "/unregserver") { - nRet = UpdateRegistry(false); - run = false; - break; - } else if (cmd == "-regserver" || cmd == "/regserver") { - nRet = UpdateRegistry(true); - run = false; - break; - } else if (cmd == "-dumpidl" || cmd == "/dumpidl") { - ++i; - if (i < cmds.count()) { - QByteArray outfile = cmds.at(i); + for (int i = 1; i < argc; ++i) { + const QString& arg = args[i]; + if ((arg.length() > 1) + && (arg.startsWith('-') || arg.startsWith('/'))) { + + const QString option = arg.mid(1); + + if (runServerOptions.contains(option)) { + runServer = true; + continue; + } + + if (unregisterOption == option) { + nRet = UpdateRegistry(false); + run = false; + break; + } + + if (registerOption == option) { + nRet = UpdateRegistry(true); + run = false; + break; + } + + if (dumpidlOption == option) { + run = false; ++i; - QByteArray version; - if (i < cmds.count() && (cmds.at(i) == "-version" || cmds.at(i) == "/version")) { + if (i >= argc) { + qWarning("Wrong commandline syntax: -dumpidl [-version ]"); + break; + } + const QString& outfile = args[i]; + ++i; + QString version; + if ((i < argc) + && (args[i].startsWith('-') || args[i].startsWith('/')) + && (versionOption == args[i])) { ++i; - if (i < cmds.count()) - version = cmds.at(i); - else - version = "1.0"; + if (i < argc) { + version = args[i]; + } else { + version = QString::fromLatin1("1.0"); + } } - - nRet = DumpIDL(QString::fromLatin1(outfile.constData()), QString::fromLatin1(version.constData())); - } else { - qWarning("Wrong commandline syntax: -dumpidl [-version ]"); + nRet = DumpIDL(outfile, version); + break; } - run = false; - break; - } else { - unprocessed += cmds.at(i) + ' '; } - } + unprocessedArgs.append(arg); + } if (run) { HRESULT hRes = CoInitialize(0); - - int argc; - QVector argv(8); - qWinMain(hInstance, hPrevInstance, unprocessed.data(), nShowCmd, argc, argv); + + qWinMain(hInstance, hPrevInstance, unprocessedArgs, nShowCmd); qAxInit(); - if (runServer) + if (runServer) { QAxFactory::startServer(); - nRet = ::main(argc, argv.data()); + } + + QList argvData; + QVector argv; + qWinBuildArgv(unprocessedArgs, argvData, argv); + nRet = ::main(argv.size(), argv.data()); + QAxFactory::stopServer(); qAxCleanup(); - CoUninitialize(); - + CoUninitialize(); } return nRet; --- src/corelib/kernel/qcoreapplication_win.cpp Ïò íîÿ 23 12:09:56 2012 +++ src/corelib/kernel/qcoreapplication_win.cpp Ïò ÿíâ 11 00:49:04 2013 @@ -161,18 +161,57 @@ staticCriticalSection.unlock(); } +/***************************************************************************** + QStringList qWinParseCmdLine(LPCWSTR) - Parses Windows command line. + *****************************************************************************/ +#if defined(Q_OS_WINCE) +Q_CORE_EXPORT QStringList __cdecl qWinParseCmdLine(LPCWSTR cmdLine) +#else +Q_CORE_EXPORT QStringList qWinParseCmdLine(LPCWSTR cmdLine) +#endif +{ + return qParseWinCmdLine(cmdLine); +} /***************************************************************************** + qWinBuildArgv(const QStringList&, QList&, QVector&) + - Builds argv for Windows. + *****************************************************************************/ +#if defined(Q_OS_WINCE) +Q_CORE_EXPORT void __cdecl qWinBuildArgv(const QStringList& args, + QList& argvData, QVector& argv) +#else +Q_CORE_EXPORT void qWinBuildArgv(const QStringList& args, + QList& argvData, QVector& argv) +#endif +{ + // Convert to Local8Bit for compatibility with vanilla Qt version + int argc = args.size(); + argvData.clear(); + argvData.reserve(argc); + for (int i = 0; i != argc; ++i) { + argvData.append(args[i].toLocal8Bit()); + } + // Fill the argc/argv + argv.clear(); + argv.reserve(argc); + for (int i = 0; i != argc; ++i) { + argv.append(argvData[i].data()); + } +} + +/***************************************************************************** qWinMain() - Initializes Windows. Called from WinMain() in qtmain_win.cpp *****************************************************************************/ #if defined(Q_OS_WINCE) -Q_CORE_EXPORT void __cdecl qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, - int cmdShow, int &argc, QVector &argv) +Q_CORE_EXPORT +void __cdecl qWinMain(HINSTANCE instance, HINSTANCE prevInstance, + const QStringList& args, int cmdShow) #else Q_CORE_EXPORT -void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, - int cmdShow, int &argc, QVector &argv) +void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, + const QStringList& args, int cmdShow) #endif { static bool already_called = false; @@ -186,15 +225,12 @@ // Install default debug handler qInstallMsgHandler(qWinMsgHandler); - - // Create command line - argv = qWinCmdLine(cmdParam, int(strlen(cmdParam)), argc); - appCmdShow = cmdShow; // Ignore Windows parameters Q_UNUSED(instance); - Q_UNUSED(prevInstance); + Q_UNUSED(prevInstance); + Q_UNUSED(args); } /*! --- src/corelib/kernel/qcorecmdlineargs_p.h Ïò íîÿ 23 12:09:56 2012 +++ src/corelib/kernel/qcorecmdlineargs_p.h Ïò ÿíâ 11 01:12:53 2013 @@ -61,15 +61,69 @@ #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) QT_BEGIN_INCLUDE_NAMESPACE + #include "QtCore/qvector.h" + #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) -# include "qt_windows.h" +#include "qt_windows.h" + +#if defined(Q_OS_WIN32) +#include #endif + +#endif + QT_END_INCLUDE_NAMESPACE -// template implementation of the parsing algorithm -// this is used from qcoreapplication_win.cpp and the tools (rcc, uic...) +#if defined(Q_OS_WIN32) +// Parse command line by means of Win32 API +static QStringList qParseWinCmdLine(LPCWSTR cmdLine) +{ + class WinArgListGuard + { + public: + explicit WinArgListGuard(LPWSTR* argList) : m_argList(argList) + { + } + + ~WinArgListGuard() + { + ::LocalFree(m_argList); + } + + private: + LPWSTR* m_argList; + }; // class WinArgListGuard + + int argc; + LPWSTR* winArgList = ::CommandLineToArgvW(cmdLine, &argc); + if (NULL == winArgList) { + return QStringList(); + } + + WinArgListGuard winArgListGuard(winArgList); + QStringList args; + args.reserve(argc); + for (int i = 0; i < argc; ++i) { + args.append(QString::fromWCharArray(winArgList[i])); + } + + return args; +} + +#elif defined(Q_OS_WINCE) + +// Emulate parsing of command line by means of Win32 API under WinCE +static QStringList qParseWinCmdLine(LPCWSTR cmdLine) +{ + //todo: implement parsing for Windows CE manually + return QStringList(); +} + +#else // Q_OS_SYMBIAN + +// Template implementation used for Symbion only template static QVector qWinCmdLine(Char *cmdParam, int length, int &argc) { @@ -132,34 +186,46 @@ return argv; } +#endif + #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) -static inline QStringList qWinCmdArgs(QString cmdLine) // not const-ref: this might be modified + +static inline QStringList qWinCmdArgs(const QString& cmdLine) { - QStringList args; - - int argc = 0; - QVector argv = qWinCmdLine((wchar_t *)cmdLine.utf16(), cmdLine.length(), argc); - for (int a = 0; a < argc; ++a) { - args << QString::fromWCharArray(argv[a]); - } - - return args; + return qParseWinCmdLine(reinterpret_cast(cmdLine.utf16())); } static inline QStringList qCmdLineArgs(int argc, char *argv[]) { Q_UNUSED(argc) Q_UNUSED(argv) - QString cmdLine = QString::fromWCharArray(GetCommandLine()); - return qWinCmdArgs(cmdLine); -} + + QStringList args = qParseWinCmdLine(::GetCommandLineW()); + +#if defined(Q_OS_WINCE) + // At Windows CE GetCommandLine doesn't return module file name (?) + wchar_t appName[MAX_PATH]; + if (::GetModuleFileNameW(0, appName, MAX_PATH)) { + // Let the module file name be the first arg + args.prepend(QString::fromWCharArray(appName)); + } else { + // Failed to obtain module file name + args.prepend(QString()); + } #endif -#else // !Q_OS_WIN || !Q_OS_SYMBIAN + return args; +} + +#endif // defined(Q_OS_WIN32) || defined(Q_OS_WINCE) + +#else // !Q_OS_WIN && !Q_OS_SYMBIAN + static inline QStringList qCmdLineArgs(int argc, char *argv[]) { QStringList args; - for (int i = 0; i != argc; ++i) + args.reserve(argc); + for (int i = 0; i != argc; ++i) args += QString::fromLocal8Bit(argv[i]); return args; } --- src/winmain/qtmain_win.cpp Ïò íîÿ 23 12:09:54 2012 +++ src/winmain/qtmain_win.cpp Ïò ÿíâ 11 02:00:05 2013 @@ -41,6 +41,8 @@ #include "qt_windows.h" #include "qbytearray.h" #include "qstring.h" +#include "qlist.h" +#include "qstringlist.h" #include "qvector.h" /* @@ -56,11 +58,27 @@ QT_BEGIN_NAMESPACE #if defined(Q_OS_WINCE) -extern void __cdecl qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector &); +extern QStringList __cdecl qWinParseCmdLine(LPCWSTR cmdLine); #else -extern void qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector &); +extern QStringList qWinParseCmdLine(LPCWSTR cmdLine); #endif +#if defined(Q_OS_WINCE) +Q_CORE_EXPORT void __cdecl qWinBuildArgv(const QStringList& args, + QList& argvData, QVector& argv); +#else +Q_CORE_EXPORT void qWinBuildArgv(const QStringList& args, + QList& argvData, QVector& argv); +#endif + +#if defined(Q_OS_WINCE) +extern void __cdecl qWinMain(HINSTANCE instance, HINSTANCE prevInstance, + const QStringList& args, int cmdShow); +#else +extern void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, + const QStringList& args, int cmdShow); +#endif + QT_END_NAMESPACE QT_USE_NAMESPACE @@ -90,17 +108,22 @@ int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /*cmdParamarg*/, int cmdShow) #endif { - QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit(); - + LPWSTR winCommandLine = ::GetCommandLineW(); + const QStringList args = qWinParseCmdLine(winCommandLine); + #if defined(Q_OS_WINCE) + // At Windows CE GetCommandLine doesn't return module file name (?) wchar_t appName[MAX_PATH]; - GetModuleFileName(0, appName, MAX_PATH); - cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit()); + if (::GetModuleFileNameW(0, appName, MAX_PATH)) { + // Let the module file name be the first arg + args.prepend(QString::fromWCharArray(appName)); + } else { + // Failed to obtain module file name + args.prepend(QString()); + } #endif - int argc = 0; - QVector argv(8); - qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv); + qWinMain(instance, prevInstance, args, cmdShow); #if defined(Q_OS_WINCE) wchar_t uniqueAppID[MAX_PATH]; @@ -128,9 +151,13 @@ } #endif // Q_OS_WINCE - int result = main(argc, argv.data()); + QList argvData; + QVector argv; + qWinBuildArgv(args, argvData, argv); + int result = main(argv.size(), argv.data()); + #if defined(Q_OS_WINCE) CloseHandle(mutex); #endif return result; -} +} \ No newline at end of file --- src/tools/rcc/rcc.pro Ïò íîÿ 23 12:09:54 2012 +++ src/tools/rcc/rcc.pro Ïò ÿíâ 11 01:16:10 2013 @@ -14,3 +14,5 @@ target.path=$$[QT_INSTALL_BINS] INSTALLS += target include(../../qt_targets.pri) + +win32:LIBS += -lshell32 \ No newline at end of file