]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/utilsexc.cpp
support for Mac Help Button added (wxID_HELP) is automatically translated
[wxWidgets.git] / src / msw / utilsexc.cpp
index b2fbf1d0606f0f6ef07e0780fab207fbe622a2ce..4dcec53bde5bb06ccef8b037593a0af3886ae2f2 100644 (file)
@@ -5,7 +5,7 @@
 // Modified by:
 // Created:     04/01/98
 // RCS-ID:      $Id$
-// Copyright:   (c) 1998-2002 wxWindows dev team
+// Copyright:   (c) 1998-2002 wxWidgets dev team
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -83,7 +83,7 @@
 #endif // wxUSE_IPC
 
 // implemented in utils.cpp
-extern "C" HWND
+extern "C" WXDLLIMPEXP_BASE HWND
 wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc);
 
 // ----------------------------------------------------------------------------
@@ -113,12 +113,10 @@ struct wxExecuteData
 public:
     ~wxExecuteData()
     {
-#ifndef __WIN16__
         if ( !::CloseHandle(hProcess) )
         {
             wxLogLastError(wxT("CloseHandle(hProcess)"));
         }
-#endif
     }
 
     HWND       hWnd;          // window to send wxWM_PROC_TERMINATED to
@@ -237,21 +235,12 @@ public:
     bool IsOk() const { return m_handles[Read] != INVALID_HANDLE_VALUE; }
 
     // return the descriptor for one of the pipe ends
-    HANDLE operator[](Direction which) const
-    {
-        wxASSERT_MSG( which >= 0 && (size_t)which < WXSIZEOF(m_handles),
-                      _T("invalid pipe index") );
-
-        return m_handles[which];
-    }
+    HANDLE operator[](Direction which) const { return m_handles[which]; }
 
     // detach a descriptor, meaning that the pipe dtor won't close it, and
     // return it
     HANDLE Detach(Direction which)
     {
-        wxASSERT_MSG( which >= 0 && (size_t)which < WXSIZEOF(m_handles),
-                      _T("invalid pipe index") );
-
         HANDLE handle = m_handles[which];
         m_handles[which] = INVALID_HANDLE_VALUE;
 
@@ -438,6 +427,21 @@ size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
 wxPipeOutputStream::wxPipeOutputStream(HANDLE hOutput)
 {
     m_hOutput = hOutput;
+
+    // unblock the pipe to prevent deadlocks when we're writing to the pipe
+    // from which the child process can't read because it is writing in its own
+    // end of it
+    DWORD mode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
+    if ( !::SetNamedPipeHandleState
+            (
+                m_hOutput,
+                &mode,
+                NULL,       // collection count (we don't set it)
+                NULL        // timeout (we don't set it neither)
+            ) )
+    {
+        wxLogLastError(_T("SetNamedPipeHandleState(PIPE_NOWAIT)"));
+    }
 }
 
 wxPipeOutputStream::~wxPipeOutputStream()
@@ -447,17 +451,29 @@ wxPipeOutputStream::~wxPipeOutputStream()
 
 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) )
+
+    DWORD totalWritten = 0;
+    while ( len > 0 )
     {
-        m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
-                            ? wxSTREAM_EOF
-                            : wxSTREAM_WRITE_ERROR;
+        DWORD chunkWritten;
+        if ( !::WriteFile(m_hOutput, buffer, len, &chunkWritten, NULL) )
+        {
+            m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
+                                ? wxSTREAM_EOF
+                                : wxSTREAM_WRITE_ERROR;
+            break;
+        }
+
+        if ( !chunkWritten )
+            break;
+
+        buffer = (char *)buffer + chunkWritten;
+        totalWritten += chunkWritten;
+        len -= chunkWritten;
     }
 
-    return bytesWritten;
+    return totalWritten;
 }
 
 #endif // wxUSE_STREAMS
@@ -473,7 +489,7 @@ static bool wxExecuteDDE(const wxString& ddeServer,
                          const wxString& ddeTopic,
                          const wxString& ddeCommand)
 {
-    bool ok = FALSE;
+    bool ok wxDUMMY_INITIALIZE(false);
 
     wxDDEClient client;
     wxConnectionBase *conn = client.MakeConnection(wxEmptyString,