+ wxPipeInputStream *self = wxConstCast(this, wxPipeInputStream);
+
+ self->m_hInput = INVALID_HANDLE_VALUE;
+ self->m_lasterror = wxSTREAM_EOF;
+
+ nAvailable = 0;
+ }
+
+ return nAvailable != 0;
+}
+
+size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
+{
+ if ( !IsOpened() )
+ {
+ m_lasterror = wxSTREAM_EOF;
+
+ return 0;
+ }
+
+ DWORD bytesRead;
+ if ( !::ReadFile(m_hInput, buffer, len, &bytesRead, NULL) )
+ {
+ m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
+ ? wxSTREAM_EOF
+ : wxSTREAM_READ_ERROR;
+ }
+
+ // bytesRead is set to 0, as desired, if an error occured
+ return bytesRead;
+}
+
+// ----------------------------------------------------------------------------
+// wxPipeOutputStream
+// ----------------------------------------------------------------------------
+
+wxPipeOutputStream::wxPipeOutputStream(HANDLE hOutput)
+{
+ m_hOutput = hOutput;
+}
+
+wxPipeOutputStream::~wxPipeOutputStream()
+{
+ ::CloseHandle(m_hOutput);
+}
+
+size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
+{
+ DWORD bytesWritten;
+
+ m_lasterror = wxSTREAM_NO_ERROR;
+ if ( !::WriteFile(m_hOutput, buffer, len, &bytesWritten, NULL) )
+ {
+ m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
+ ? wxSTREAM_EOF
+ : wxSTREAM_WRITE_ERROR;
+ }
+
+ return bytesWritten;
+}
+
+#endif // wxUSE_STREAMS
+
+#endif // Win32
+
+// ============================================================================
+// wxExecute functions family
+// ============================================================================
+
+#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 = FALSE;
+
+ 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 one first and then the other one if it
+ // failed
+ {
+ wxLogNull noErrors;
+ ok = conn->Execute(ddeCommand);
+ }
+
+ if ( !ok )
+ {
+ // now try request - but show the errors
+ ok = conn->Request(ddeCommand) != NULL;
+ }
+ }
+
+ return ok;
+}
+
+#endif // wxUSE_IPC
+
+long wxExecute(const wxString& cmd, int flags, 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
+ // returns the command which should be run to view/open/... a file of the
+ // 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
+ // 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('#') )
+ {
+ command += *p++;
+ }
+
+ if ( *p )
+ {
+ // skip '#'
+ p++;
+ }
+ else
+ {
+ wxFAIL_MSG(_T("invalid WX_DDE command in wxExecute"));
+ }
+
+ while ( *p && *p != _T('#') )
+ {
+ ddeServer += *p++;
+ }
+
+ if ( *p )
+ {
+ // skip '#'
+ p++;
+ }
+ else
+ {
+ wxFAIL_MSG(_T("invalid WX_DDE command in wxExecute"));