#include <ctype.h>
-#if !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__SALFORDC__)
+#if !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__SALFORDC__) && !defined(__WXMICROWIN__)
#include <direct.h>
#ifndef __MWERKS__
#include <dos.h>
#include <sys/stat.h>
#endif
-#if defined(__WIN32__) && !defined(__WXWINE__)
+#if defined(__WIN32__) && !defined(__WXWINE__) && !defined(__WXMICROWIN__)
#include <io.h>
#ifndef __GNUWIN32__
#ifdef __WIN32__
-static DWORD wxExecuteThread(wxExecuteData *data)
+static DWORD __stdcall wxExecuteThread(void *arg)
{
+ wxExecuteData *data = (wxExecuteData*)arg;
+
WaitForSingleObject(data->hProcess, INFINITE);
// get the exit code
#endif // wxUSE_IPC
-long wxExecute(const wxString& cmd, bool sync, wxProcess *handler)
+long wxExecute(const wxString& cmd, int flags, wxProcess *handler)
{
wxCHECK_MSG( !!cmd, 0, wxT("empty command in wxExecute") );
// termination, try to execute DDE command right now, it can succeed if
// the process is already running - but as it fails if it's not
// running, suppress any errors it might generate
- if ( !sync )
+ if ( !(flags & wxEXEC_SYNC) )
{
wxLogNull noErrors;
if ( wxExecuteDDE(ddeServer, ddeTopic, ddeCommand) )
{
wxLogSysError(_("Can't create the inter-process read pipe"));
- // indicate failure in both cases
- return sync ? -1 : 0;
+ // indicate failure: we need to return different error code
+ // depending on the sync flag
+ return flags & wxEXEC_SYNC ? -1 : 0;
}
// and a stdout one
wxLogSysError(_("Can't create the inter-process write pipe"));
- return sync ? -1 : 0;
+ return flags & wxEXEC_SYNC ? -1 : 0;
}
(void)::CreatePipe(&hpipeStderr[0], &hpipeStderr[1], &security, 0);
#if wxUSE_STREAMS
if ( redirect )
{
- // when the std IO is redirected, we don't show the (console) process
- // window
- si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = hpipeStdin[0];
si.hStdOutput = hpipeStdout[1];
si.hStdError = hpipeStderr[1];
- si.wShowWindow = SW_HIDE;
+ // when the std IO is redirected, we don't show the (console) process
+ // window by default, but this can be overridden by the caller by
+ // specifying wxEXEC_NOHIDE flag
+ if ( !(flags & wxEXEC_NOHIDE) )
+ {
+ si.dwFlags |= STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+ }
// we must duplicate the handle to the write side of stdin pipe to make
// it non inheritable: indeed, we must close hpipeStdin[1] before
wxLogSysError(_("Execution of command '%s' failed"), command.c_str());
- return sync ? -1 : 0;
+ return flags & wxEXEC_SYNC ? -1 : 0;
}
#if wxUSE_STREAMS
data->hProcess = pi.hProcess;
data->dwProcessId = pi.dwProcessId;
data->hWnd = hwnd;
- data->state = sync;
- if ( sync )
+ data->state = (flags & wxEXEC_SYNC) != 0;
+ if ( flags & wxEXEC_SYNC )
{
// handler may be !NULL for capturing program output, but we don't use
// it wxExecuteData struct in this case
DWORD tid;
HANDLE hThread = ::CreateThread(NULL,
0,
- (LPTHREAD_START_ROUTINE)wxExecuteThread,
+ wxExecuteThread,
(void *)data,
0,
&tid);
// ok, process ready to accept DDE requests
ok = wxExecuteDDE(ddeServer, ddeTopic, ddeCommand);
}
-
- if ( !ok )
- {
- // FIXME just as above we don't check Execute() return code
- wxLogNull nolog;
- (void)conn->Execute(ddeCommand);
- }
}
#endif // wxUSE_IPC
- if ( !sync )
+ if ( !(flags & wxEXEC_SYNC) )
{
// clean up will be done when the process terminates
#endif // wxUSE_GUI
while ( data->state )
+ {
+ // don't take 100% of the CPU
+ ::Sleep(500);
wxYield();
+ }
#if wxUSE_GUI
}
return dwExitCode;
#else // Win16
long instanceID = WinExec((LPCSTR) WXSTRINGCAST command, SW_SHOW);
- if (instanceID < 32) return(0);
+ if (instanceID < 32)
+ return flags & wxEXEC_SYNC ? -1 : 0;
- if (sync) {
+ if ( flags & wxEXEC_SYNC )
+ {
int running;
- do {
+ do
+ {
wxYield();
running = GetModuleUsage((HINSTANCE)instanceID);
} while (running);
}
- return(instanceID);
+ return instanceID;
#endif // Win16/32
}
-long wxExecute(char **argv, bool sync, wxProcess *handler)
+long wxExecute(char **argv, int flags, wxProcess *handler)
{
wxString command;
command.RemoveLast();
- return wxExecute(command, sync, handler);
+ return wxExecute(command, flags, handler);
}
-#if wxUSE_GUI
-
-// ----------------------------------------------------------------------------
-// Metafile helpers
-// ----------------------------------------------------------------------------
-
-extern void PixelToHIMETRIC(LONG *x, LONG *y)
-{
- ScreenHDC hdcRef;
-
- int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE),
- iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE),
- iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
- iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
-
- *x *= (iWidthMM * 100);
- *x /= iWidthPels;
- *y *= (iHeightMM * 100);
- *y /= iHeightPels;
-}
-
-extern void HIMETRICToPixel(LONG *x, LONG *y)
-{
- ScreenHDC hdcRef;
-
- int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE),
- iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE),
- iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
- iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
-
- *x *= iWidthPels;
- *x /= (iWidthMM * 100);
- *y *= iHeightPels;
- *y /= (iHeightMM * 100);
-}
-
-#endif // wxUSE_GUI