[Win] Fix the command line spliting code.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 16 Aug 2013 10:48:02 +0000 (18:48 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 16 Aug 2013 10:48:02 +0000 (18:48 +0800)
app/atom_main.cc

index 34e3b63..618e54b 100644 (file)
@@ -13,22 +13,23 @@ int Start(int argc, char *argv[]);
 #if defined(OS_WIN)
 
 #include <windows.h>  // NOLINT
+#include <shellapi.h>  // NOLINT
 
 #include "app/atom_main_delegate.h"
 #include "content/public/app/startup_helper_win.h"
 #include "sandbox/win/src/sandbox_types.h"
 
-int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* wargv, int argc) {
-  const wchar_t* wargv1 = reinterpret_cast<const wchar_t*>(wargv[1]);
-  if (argc > 1 && wcscmp(wargv1, L"--atom-child_process-fork") == 0) {
+int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
+  int argc = 0;
+  wchar_t** wargv = ::CommandLineToArgvW(cmd, &argc);
+  if (argc > 1 && wcscmp(wargv[1], L"--atom-child_process-fork") == 0) {
     // Convert argv to to UTF8
     char** argv = new char*[argc];
     for (int i = 0; i < argc; i++) {
-      const wchar_t* wargvi = reinterpret_cast<const wchar_t*>(wargv[i]);
       // Compute the size of the required buffer
       DWORD size = WideCharToMultiByte(CP_UTF8,
                                        0,
-                                       wargvi,
+                                       wargv[i],
                                        -1,
                                        NULL,
                                        0,
@@ -43,7 +44,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* wargv, int argc) {
       argv[i] = new char[size];
       DWORD result = WideCharToMultiByte(CP_UTF8,
                                          0,
-                                         wargvi,
+                                         wargv[i],
                                          -1,
                                          argv[i],
                                          size,