-// Execute a command (e.g. another program) in a
-// system-independent manner.
-
-long wxExecute(char **argv, bool sync)
-{
- if (*argv == NULL)
- return 0;
-
- char command[1024];
- command[0] = '\0';
-
- int argc;
- for (argc = 0; argv[argc]; argc++)
- {
- if (argc)
- strcat(command, " ");
- strcat(command, argv[argc]);
- }
-
- return wxExecute((char *)command, sync);
-}
-
-long wxExecute(const wxString& command, bool sync)
-{
- if (command == "")
- return 0;
-
-#ifdef __WIN32__
- char * cl;
- char * argp;
- int clen;
- HINSTANCE result;
- DWORD dresult;
-
- // copy the command line
- clen = command.Length();
- if (!clen) return -1;
- cl = (char *) calloc( 1, 256);
- if (!cl) return -1;
- strcpy( cl, WXSTRINGCAST command);
-
- // isolate command and arguments
- argp = strchr( cl, ' ');
- if (argp)
- *argp++ = '\0';
-
- // execute the command
-#ifdef __GNUWIN32__
- result = ShellExecute( (HWND) (wxTheApp->GetTopWindow() ? (HWND) wxTheApp->GetTopWindow()->GetHWND() : NULL),
- (const wchar_t) "open", (const wchar_t) cl, (const wchar_t) argp, (const wchar_t) NULL, SW_SHOWNORMAL);
-#else
- result = ShellExecute( (HWND) (wxTheApp->GetTopWindow() ? wxTheApp->GetTopWindow()->GetHWND() : NULL),
- "open", cl, argp, NULL, SW_SHOWNORMAL);
-#endif
-
- if (((long)result) <= 32) {
- free(cl);
- return 0;
- }
-
- if (!sync)
- {
- free(cl);
- return dresult;
- }
-
- // waiting until command executed
- do {
- wxYield();
- dresult = GetModuleFileName( result, cl, 256);
- } while( dresult);
-
- /* long lastError = GetLastError(); */
-
- free(cl);
- return 0;
-#else
- long instanceID = WinExec((LPCSTR) WXSTRINGCAST command, SW_SHOW);
- if (instanceID < 32) return(0);
-
- if (sync) {
- int running;
- do {
- wxYield();
- running = GetModuleUsage((HANDLE)instanceID);
- } while (running);
- }
- return(instanceID);
-#endif
-}
-