Index: /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp	(revision 78167)
+++ /trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp	(revision 78168)
@@ -174,5 +174,6 @@
     LRESULT rc = 0;
 
-    PVBOXCLIPBOARDCONTEXT pCtx = &g_ctx;
+    const PVBOXCLIPBOARDCONTEXT pCtx    = &g_ctx;
+    const PVBOXCLIPBOARDWINCTX  pWinCtx = &pCtx->Win;
 
     switch (msg)
@@ -194,5 +195,5 @@
             Log(("WM_CHANGECBCHAIN\n"));
 
-            if (VBoxClipboardWinIsNewAPI(&pCtx->Win.newAPI))
+            if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI))
             {
                 rc = DefWindowProc(hwnd, msg, wParam, lParam);
@@ -203,18 +204,18 @@
             HWND hwndNext    = (HWND)lParam;
 
-            if (hwndRemoved == pCtx->Win.hWndNextInChain)
+            if (hwndRemoved == pWinCtx->hWndNextInChain)
             {
                 /* The window that was next to our in the chain is being removed.
                  * Relink to the new next window.
                  */
-                pCtx->Win.hWndNextInChain = hwndNext;
+                pWinCtx->hWndNextInChain = hwndNext;
             }
             else
             {
-                if (pCtx->Win.hWndNextInChain)
+                if (pWinCtx->hWndNextInChain)
                 {
                     /* Pass the message further. */
                     DWORD_PTR dwResult;
-                    rc = SendMessageTimeout(pCtx->Win.hWndNextInChain, WM_CHANGECBCHAIN, wParam, lParam, 0,
+                    rc = SendMessageTimeout(pWinCtx->hWndNextInChain, WM_CHANGECBCHAIN, wParam, lParam, 0,
                                             VBOX_CLIPBOARD_CBCHAIN_TIMEOUT_MS,
                                             &dwResult);
@@ -236,10 +237,10 @@
             }
 
-            if (pCtx->Win.hWndNextInChain)
-            {
-                Log(("WM_DRAWCLIPBOARD next %p\n", pCtx->Win.hWndNextInChain));
+            if (pWinCtx->hWndNextInChain)
+            {
+                Log(("WM_DRAWCLIPBOARD next %p\n", pWinCtx->hWndNextInChain));
                 /* Pass the message to next windows in the clipboard chain. */
                 DWORD_PTR dwResult;
-                rc = SendMessageTimeout(pCtx->Win.hWndNextInChain, msg, wParam, lParam, 0, VBOX_CLIPBOARD_CBCHAIN_TIMEOUT_MS,
+                rc = SendMessageTimeout(pWinCtx->hWndNextInChain, msg, wParam, lParam, 0, VBOX_CLIPBOARD_CBCHAIN_TIMEOUT_MS,
                                         &dwResult);
                 if (!rc)
@@ -250,5 +251,5 @@
         case WM_TIMER:
         {
-            if (VBoxClipboardWinIsNewAPI(&pCtx->Win.newAPI))
+            if (VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI))
                 break;
 
@@ -257,5 +258,5 @@
             /* Re-register ourselves in the clipboard chain if our last ping
              * timed out or there seems to be no valid chain. */
-            if (!hViewer || pCtx->Win.oldAPI.fCBChainPingInProcess)
+            if (!hViewer || pWinCtx->oldAPI.fCBChainPingInProcess)
             {
                 VBoxClipboardWinRemoveFromCBChain(&pCtx->Win);
@@ -265,11 +266,11 @@
             /* Start a new ping by passing a dummy WM_CHANGECBCHAIN to be
              * processed by ourselves to the chain. */
-            pCtx->Win.oldAPI.fCBChainPingInProcess = TRUE;
+            pWinCtx->oldAPI.fCBChainPingInProcess = TRUE;
 
             hViewer = GetClipboardViewer();
             if (hViewer)
                 SendMessageCallback(hViewer, WM_CHANGECBCHAIN,
-                                    (WPARAM)pCtx->Win.hWndNextInChain, (LPARAM)pCtx->Win.hWndNextInChain,
-                                    VBoxClipboardWinChainPingProc, (ULONG_PTR)pCtx);
+                                    (WPARAM)pWinCtx->hWndNextInChain, (LPARAM)pWinCtx->hWndNextInChain,
+                                    VBoxClipboardWinChainPingProc, (ULONG_PTR)pWinCtx);
         } break;
 
@@ -454,8 +455,8 @@
             /* MS recommends to remove from Clipboard chain in this callback. */
             VBoxClipboardWinRemoveFromCBChain(&pCtx->Win);
-            if (pCtx->Win.oldAPI.timerRefresh)
-            {
-                Assert(pCtx->Win.hWnd);
-                KillTimer(pCtx->Win.hWnd, 0);
+            if (pWinCtx->oldAPI.timerRefresh)
+            {
+                Assert(pWinCtx->hWnd);
+                KillTimer(pWinCtx->hWnd, 0);
             }
             PostQuitMessage(0);
@@ -481,5 +482,6 @@
     LogFlow(("VBoxClipboardThread\n"));
 
-    const PVBOXCLIPBOARDCONTEXT pCtx = &g_ctx;
+    const PVBOXCLIPBOARDCONTEXT pCtx    = &g_ctx;
+    const PVBOXCLIPBOARDWINCTX  pWinCtx = &pCtx->Win;
 
     HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
@@ -505,9 +507,9 @@
     {
         /* Create the window. */
-        pCtx->Win.hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
-                                         s_szClipWndClassName, s_szClipWndClassName,
-                                         WS_POPUPWINDOW,
-                                         -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
-        if (pCtx->Win.hWnd == NULL)
+        pWinCtx->hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
+                                        s_szClipWndClassName, s_szClipWndClassName,
+                                        WS_POPUPWINDOW,
+                                        -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
+        if (pWinCtx->hWnd == NULL)
         {
             Log(("Failed to create window\n"));
@@ -516,10 +518,10 @@
         else
         {
-            SetWindowPos(pCtx->Win.hWnd, HWND_TOPMOST, -200, -200, 0, 0,
+            SetWindowPos(pWinCtx->hWnd, HWND_TOPMOST, -200, -200, 0, 0,
                          SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
 
             VBoxClipboardWinAddToCBChain(&pCtx->Win);
-            if (!VBoxClipboardWinIsNewAPI(&pCtx->Win.newAPI))
-                pCtx->Win.oldAPI.timerRefresh = SetTimer(pCtx->Win.hWnd, 0, 10 * 1000, NULL);
+            if (!VBoxClipboardWinIsNewAPI(&pWinCtx->newAPI))
+                pWinCtx->oldAPI.timerRefresh = SetTimer(pWinCtx->hWnd, 0, 10 * 1000, NULL);
 
             MSG msg;
@@ -540,5 +542,5 @@
     }
 
-    pCtx->Win.hWnd = NULL;
+    pWinCtx->hWnd = NULL;
 
     if (atomWindowClass != 0)
@@ -652,4 +654,7 @@
 void vboxClipboardFormatAnnounce (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Formats)
 {
+    AssertPtrReturnVoid(pClient);
+    AssertPtrReturnVoid(pClient->pCtx);
+
     /*
      * The guest announces formats. Forward to the window thread.
@@ -690,12 +695,17 @@
 int vboxClipboardReadData (VBOXCLIPBOARDCLIENTDATA *pClient, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual)
 {
+    AssertPtrReturn(pClient,       VERR_INVALID_POINTER);
+    AssertPtrReturn(pClient->pCtx, VERR_INVALID_POINTER);
+
     LogFlow(("vboxClipboardReadData: u32Format = %02X\n", u32Format));
 
     HANDLE hClip = NULL;
+
+    const PVBOXCLIPBOARDWINCTX pWinCtx = &pClient->pCtx->Win;
 
     /*
      * The guest wants to read data in the given format.
      */
-    int rc = VBoxClipboardWinOpen(pClient->pCtx->Win.hWnd);
+    int rc = VBoxClipboardWinOpen(pWinCtx->hWnd);
     if (RT_SUCCESS(rc))
     {
