Index: trunk/src/VBox/Devices/Serial/DrvNamedPipe.cpp
===================================================================
--- trunk/src/VBox/Devices/Serial/DrvNamedPipe.cpp	(revision 18442)
+++ trunk/src/VBox/Devices/Serial/DrvNamedPipe.cpp	(revision 18443)
@@ -100,9 +100,9 @@
 
 /** @copydoc PDMISTREAM::pfnRead */
-static DECLCALLBACK(int) drvNamedPipeRead(PPDMISTREAM pInterface, void *pvBuf, size_t *cbRead)
+static DECLCALLBACK(int) drvNamedPipeRead(PPDMISTREAM pInterface, void *pvBuf, size_t *pcbRead)
 {
     int rc = VINF_SUCCESS;
     PDRVNAMEDPIPE pThis = PDMISTREAM_2_DRVNAMEDPIPE(pInterface);
-    LogFlow(("%s: pvBuf=%p cbRead=%#x (%s)\n", __FUNCTION__, pvBuf, cbRead, pThis->pszLocation));
+    LogFlow(("%s: pvBuf=%p *pcbRead=%#x (%s)\n", __FUNCTION__, pvBuf, *pcbRead, pThis->pszLocation));
 
     Assert(pvBuf);
@@ -113,5 +113,5 @@
         pThis->OverlappedRead.Offset     = 0;
         pThis->OverlappedRead.OffsetHigh = 0;
-        if (!ReadFile(pThis->NamedPipe, pvBuf, *cbRead, &cbReallyRead, &pThis->OverlappedRead))
+        if (!ReadFile(pThis->NamedPipe, pvBuf, (DWORD)*pcbRead, &cbReallyRead, &pThis->OverlappedRead))
         {
             DWORD uError = GetLastError();
@@ -164,5 +164,5 @@
             cbReallyRead = 0;
         }
-        *cbRead = (size_t)cbReallyRead;
+        *pcbRead = (size_t)cbReallyRead;
     }
 #else /* !RT_OS_WINDOWS */
@@ -170,5 +170,5 @@
     {
         ssize_t cbReallyRead;
-        cbReallyRead = recv(pThis->LocalSocket, pvBuf, *cbRead, 0);
+        cbReallyRead = recv(pThis->LocalSocket, pvBuf, *pcbRead, 0);
         if (cbReallyRead == 0)
         {
@@ -182,5 +182,5 @@
             rc = RTErrConvertFromErrno(errno);
         }
-        *cbRead = cbReallyRead;
+        *pcbRead = cbReallyRead;
     }
 #endif /* !RT_OS_WINDOWS */
@@ -188,8 +188,8 @@
     {
         RTThreadSleep(100);
-        *cbRead = 0;
-    }
-
-    LogFlow(("%s: cbRead=%d returns %Rrc\n", __FUNCTION__, *cbRead, rc));
+        *pcbRead = 0;
+    }
+
+    LogFlow(("%s: *pcbRead=%zu returns %Rrc\n", __FUNCTION__, *pcbRead, rc));
     return rc;
 }
@@ -197,9 +197,9 @@
 
 /** @copydoc PDMISTREAM::pfnWrite */
-static DECLCALLBACK(int) drvNamedPipeWrite(PPDMISTREAM pInterface, const void *pvBuf, size_t *cbWrite)
+static DECLCALLBACK(int) drvNamedPipeWrite(PPDMISTREAM pInterface, const void *pvBuf, size_t *pcbWrite)
 {
     int rc = VINF_SUCCESS;
     PDRVNAMEDPIPE pThis = PDMISTREAM_2_DRVNAMEDPIPE(pInterface);
-    LogFlow(("%s: pvBuf=%p cbWrite=%#x (%s)\n", __FUNCTION__, pvBuf, cbWrite, pThis->pszLocation));
+    LogFlow(("%s: pvBuf=%p *pcbWrite=%#x (%s)\n", __FUNCTION__, pvBuf, *pcbWrite, pThis->pszLocation));
 
     Assert(pvBuf);
@@ -207,8 +207,8 @@
     if (pThis->NamedPipe != INVALID_HANDLE_VALUE)
     {
-        unsigned cbWritten;
+        DWORD cbWritten = (DWORD)*pcbWrite;
         pThis->OverlappedWrite.Offset     = 0;
         pThis->OverlappedWrite.OffsetHigh = 0;
-        if (!WriteFile(pThis->NamedPipe, pvBuf, *cbWrite, NULL, &pThis->OverlappedWrite))
+        if (!WriteFile(pThis->NamedPipe, pvBuf, cbWritten, NULL, &pThis->OverlappedWrite))
         {
             DWORD uError = GetLastError();
@@ -217,22 +217,19 @@
                 || uError == ERROR_PIPE_NOT_CONNECTED)
             {
-                /* No connection yet/anymore; just discard the write. */
-                cbWritten = *cbWrite;
-            }
-            else
-            if (uError != ERROR_IO_PENDING)
+                /* No connection yet/anymore; just discard the write (pretening everything was written). */;
+            }
+            else if (uError != ERROR_IO_PENDING)
             {
                 rc = RTErrConvertFromWin32(uError);
                 Log(("drvNamedPipeWrite: WriteFile returned %d (%Rrc)\n", uError, rc));
+                cbWritten = 0;
             }
             else
             {
                 /* Wait for the write to complete. */
-                if (GetOverlappedResult(pThis->NamedPipe, &pThis->OverlappedWrite, (DWORD *)&cbWritten, TRUE) == FALSE)
-                    uError = GetLastError();
-            }
-        }
-        else
-            cbWritten = *cbWrite;
+                if (GetOverlappedResult(pThis->NamedPipe, &pThis->OverlappedWrite, &cbWritten, TRUE /*bWait*/) == FALSE)
+                    rc = RTErrConvertFromWin32(uError = GetLastError());
+            }
+        }
 
         if (RT_FAILURE(rc))
@@ -253,5 +250,5 @@
             cbWritten = 0;
         }
-        *cbWrite = cbWritten;
+        *pcbWrite = cbWritten;
     }
 #else /* !RT_OS_WINDOWS */
@@ -259,5 +256,5 @@
     {
         ssize_t cbWritten;
-        cbWritten = send(pThis->LocalSocket, pvBuf, *cbWrite, 0);
+        cbWritten = send(pThis->LocalSocket, pvBuf, *pcbWrite, 0);
         if (cbWritten == 0)
         {
@@ -271,5 +268,5 @@
             rc = RTErrConvertFromErrno(errno);
         }
-        *cbWrite = cbWritten;
+        *pcbWrite = cbWritten;
     }
 #endif /* !RT_OS_WINDOWS */
