}
#endif // Win32
+#if wxUSE_IPC
+
+// connect to the given server via DDE and ask it to execute the command
+static bool wxExecuteDDE(const wxString& ddeServer,
+ const wxString& ddeTopic,
+ const wxString& ddeCommand)
+{
+ bool ok;
+
+ wxDDEClient client;
+ wxConnectionBase *conn = client.MakeConnection(_T(""),
+ ddeServer,
+ ddeTopic);
+ if ( !conn )
+ {
+ ok = FALSE;
+ }
+ else // connected to DDE server
+ {
+ // the added complication here is that although most
+ // programs use XTYP_EXECUTE for their DDE API, some
+ // important ones - like IE and other MS stuff - use
+ // XTYP_REQUEST!
+ //
+ // so we try it first and then the other one if it
+ // failed
+ {
+ wxLogNull noErrors;
+ ok = conn->Request(ddeCommand) != NULL;
+ }
+
+ if ( !ok )
+ {
+ // now try execute - but show the errors
+ ok = conn->Execute(ddeCommand);
+ }
+ }
+
+ return ok;
+}
+
+#endif // wxUSE_IPC
+
long wxExecute(const wxString& cmd, bool sync, wxProcess *handler)
{
wxCHECK_MSG( !!cmd, 0, wxT("empty command in wxExecute") );
wxString command;
+
#if wxUSE_IPC
// DDE hack: this is really not pretty, but we need to allow this for
// transparent handling of DDE servers in wxMimeTypesManager. Usually it
// given type. Sometimes, however, this command just launches the server
// and an additional DDE request must be made to really open the file. To
// keep all this well hidden from the application, we allow a special form
- // of command: WX_DDE:<command>:DDE_SERVER:DDE_TOPIC:DDE_COMMAND in which
+ // of command: WX_DDE#<command>#DDE_SERVER#DDE_TOPIC#DDE_COMMAND in which
// case we execute just <command> and process the rest below
wxString ddeServer, ddeTopic, ddeCommand;
static const size_t lenDdePrefix = 7; // strlen("WX_DDE:")
if ( cmd.Left(lenDdePrefix) == _T("WX_DDE#") )
{
+ // speed up the concatenations below
+ ddeServer.reserve(256);
+ ddeTopic.reserve(256);
+ ddeCommand.reserve(256);
+
const wxChar *p = cmd.c_str() + 7;
while ( *p && *p != _T('#') )
{
{
ddeCommand += *p++;
}
+
+ // if we want to just launch the program and not wait for its
+ // 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 )
+ {
+ wxLogNull noErrors;
+ if ( wxExecuteDDE(ddeServer, ddeTopic, ddeCommand) )
+ {
+ // a dummy PID - this is a hack, of course, but it's well worth
+ // it as we don't open a new server each time we're called
+ // which would be quite bad
+ return -1;
+ }
+ }
}
else
#endif // wxUSE_IPC
#if wxUSE_STREAMS
// the first elements are reading ends, the second are the writing ones
HANDLE hpipeStdin[2],
- hpipeStdinWrite = INVALID_HANDLE_VALUE,
hpipeStdout[2],
hpipeStderr[2];
+ HANDLE hpipeStdinWrite = INVALID_HANDLE_VALUE;
// open the pipes to which child process IO will be redirected if needed
if ( handler && handler->IsRedirected() )
#if wxUSE_IPC
// second part of DDE hack: now establish the DDE conversation with the
// just launched process
- if ( !!ddeServer )
+ if ( !ddeServer.empty() )
{
- wxDDEClient client;
- wxConnectionBase *conn = client.MakeConnection(_T(""),
- ddeServer,
- ddeTopic);
- if ( !conn || !conn->Execute(ddeCommand) )
+ bool ok;
+
+ // give the process the time to init itself
+ //
+ // we use a very big timeout hoping that WaitForInputIdle() will return
+ // much sooner, but not INFINITE just in case the process hangs
+ // completely - like this we will regain control sooner or later
+ switch ( ::WaitForInputIdle(pi.hProcess, 10000 /* 10 seconds */) )
{
- wxLogError(_("Couldn't launch DDE server '%s'."), command.c_str());
+ default:
+ wxFAIL_MSG( _T("unexpected WaitForInputIdle() return code") );
+ // fall through
+
+ case -1:
+ wxLogLastError(_T("WaitForInputIdle() in wxExecute"));
+
+ case WAIT_TIMEOUT:
+ wxLogDebug(_T("Timeout too small in WaitForInputIdle"));
+
+ ok = FALSE;
+ break;
+
+ case 0:
+ // ok, process ready to accept DDE requests
+ ok = wxExecuteDDE(ddeServer, ddeTopic, ddeCommand);
}
}
#endif // wxUSE_IPC
return wxExecute(command, sync, 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