From 45c0d0e6a963d3def1e2e59d6ee50f9d996ac6ec Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 9 Feb 2015 23:50:43 -0800 Subject: [PATCH] Fix Windows --url command line parameter handling --- interface/src/main.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 61278821ee..64ecb2b9e7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include #include @@ -36,7 +37,7 @@ static BOOL CALLBACK enumWindowsCallback(HWND hWnd, LPARAM lParam) { #endif -int main(int argc, const char * argv[]) { +int main(int argc, const char* argv[]) { #ifdef Q_OS_WIN // Run only one instance of Interface at a time. HANDLE mutex = CreateMutex(NULL, FALSE, "High Fidelity Interface"); @@ -46,14 +47,32 @@ int main(int argc, const char * argv[]) { HWND otherInstance = NULL; EnumWindows(enumWindowsCallback, (LPARAM)&otherInstance); if (otherInstance) { + // Show other instance. SendMessage(otherInstance, UWM_SHOW_APPLICATION, 0, 0); - QUrl url = QUrl(argv[1]); - if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { - COPYDATASTRUCT cds; - cds.cbData = strlen(argv[1]) + 1; - cds.lpData = (PVOID)argv[1]; - SendMessage(otherInstance, WM_COPYDATA, 0, (LPARAM)&cds); + // Send command line --url value to other instance. + if (argc >= 3) { + QStringList arguments; + for (int i = 0; i < argc; i += 1) { + arguments << argv[i]; + } + + QCommandLineParser parser; + QCommandLineOption urlOption("url", "", "value"); + parser.addOption(urlOption); + parser.process(arguments); + + if (parser.isSet(urlOption)) { + QUrl url = QUrl(parser.value(urlOption)); + if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { + QByteArray urlBytes = url.toString().toLatin1(); + const char* urlChars = urlBytes.data(); + COPYDATASTRUCT cds; + cds.cbData = urlBytes.length() + 1; + cds.lpData = (PVOID)urlChars; + SendMessage(otherInstance, WM_COPYDATA, 0, (LPARAM)&cds); + } + } } } return 0;