+//// Convert Windows to argc, argv style
+
+void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine)
+{
+ wxStringList args;
+
+ wxString cmdLine(lpCmdLine);
+ int count = 0;
+
+ // Get application name
+ char name[260]; // 260 is MAX_PATH value from windef.h
+ ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name));
+
+ // GNUWIN32 already fills in the first arg with the application name.
+#if !defined(__GNUWIN32__)
+ args.Add(name);
+ count ++;
+#endif
+
+ strcpy(name, wxFileNameFromPath(name));
+ wxStripExtension(name);
+ wxTheApp->SetAppName(name);
+
+ // Break up string
+ // Treat strings enclosed in double-quotes as single arguments
+ int i = 0;
+ int len = cmdLine.Length();
+ while (i < len)
+ {
+ // Skip whitespace
+ while ((i < len) && isspace(cmdLine.GetChar(i)))
+ i ++;
+
+ if (i < len)
+ {
+ if (cmdLine.GetChar(i) == '"') // We found the start of a string
+ {
+ i ++;
+ int first = i;
+ while ((i < len) && (cmdLine.GetChar(i) != '"'))
+ i ++;
+
+ wxString arg(cmdLine.Mid(first, (i - first)));
+
+ args.Add(arg);
+ count ++;
+
+ if (i < len)
+ i ++; // Skip past 2nd quote
+ }
+ else // Unquoted argument
+ {
+ int first = i;
+ while ((i < len) && !isspace(cmdLine.GetChar(i)))
+ i ++;
+
+ wxString arg(cmdLine.Mid(first, (i - first)));
+
+ args.Add(arg);
+ count ++;
+ }
+ }
+ }
+
+ wxTheApp->argv = new char*[count + 1];
+ for (i = 0; i < count; i++)
+ {
+ wxString arg(args[i]);
+ wxTheApp->argv[i] = copystring((const char*)arg);
+ }
+ wxTheApp->argv[count] = NULL; // argv[] is a NULL-terminated list
+ wxTheApp->argc = count;
+}
+
+//// Cleans up any wxWindows internal structures left lying around
+