Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceClipboard-os2.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceClipboard-os2.cpp	(revision 43580)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceClipboard-os2.cpp	(revision 43581)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2007 Oracle Corporation
+ * Copyright (C) 2007-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -170,4 +170,6 @@
     if (g_hmqCtrl != NULLHANDLE)
     {
+        WinCancelShutdown(g_hmqCtrl, TRUE); /* We don't care about shutdown */
+
         /*
          * Create the 'nothing-changed' format.
@@ -811,4 +813,6 @@
         if (g_hmqListener != NULLHANDLE)
         {
+            WinCancelShutdown(g_hmqListener, TRUE); /* We don't care about shutdown */
+
             /*
              * Tell the worker thread that we're good.
@@ -903,4 +907,7 @@
         if (g_hmqWorker != NULLHANDLE)
         {
+            if (g_hmqWorker != g_hmqCtrl)
+                WinCancelShutdown(g_hmqWorker, TRUE); /* We don't care about shutdown */
+
             /*
              * Create the object window.
@@ -949,5 +956,10 @@
                             QMSG qmsg;
                             while (WinGetMsg(g_habWorker, &qmsg, NULLHANDLE, NULLHANDLE, 0))
+                            {
+                                if (qmsg.msg != WM_TIMER)
+                                    VBoxServiceVerbose(6, "WinGetMsg -> hwnd=%p msg=%#x mp1=%p mp2=%p time=%#x ptl=%d,%d rsrv=%#x\n", 
+                                                       qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2, qmsg.time, qmsg.ptl.x, qmsg.ptl.y, qmsg.reserved);  
                                 WinDispatchMsg(g_habWorker, &qmsg);
+                            }
                             VBoxServiceVerbose(2, "clipboard: Exited PM message loop. *pfShutdown=%RTbool\n", *pfShutdown);
 
@@ -997,4 +1009,19 @@
         &&  !WinPostQueueMsg(g_hmqWorker, WM_QUIT, NULL, NULL))
         VBoxServiceError("WinPostQueueMsg(g_hmqWorker, WM_QUIT, 0,0) failed, lasterr=%lx\n", WinGetLastError(g_habCtrl));
+
+    /* Must disconnect the clipboard here otherwise the listner won't quit and
+       the service shutdown will not stop. */
+    if (g_u32ClientId != 0)
+    {
+        if (g_hmqWorker != NULLHANDLE)
+            RTThreadSleep(32);      /* fudge */
+
+        VBoxServiceVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId);
+        int rc = VbglR3ClipboardDisconnect(g_u32ClientId);
+        if (RT_SUCCESS(rc))
+            g_u32ClientId = 0;
+        else
+            VBoxServiceError("clipboard: VbglR3ClipboardDisconnect(%#x) -> %Rrc\n", g_u32ClientId, rc);
+    }
 }
 
@@ -1003,7 +1030,13 @@
 static DECLCALLBACK(void) VBoxServiceClipboardOS2Term(void)
 {
-    VBoxServiceVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId);
-    VbglR3ClipboardDisconnect(g_u32ClientId);
-    g_u32ClientId = 0;
+    if (g_u32ClientId != 0)
+    {
+        VBoxServiceVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId);
+        int rc = VbglR3ClipboardDisconnect(g_u32ClientId);
+        if (RT_SUCCESS(rc))
+            g_u32ClientId = 0;
+        else
+            VBoxServiceError("clipboard: VbglR3ClipboardDisconnect(%#x) -> %Rrc\n", g_u32ClientId, rc);
+    }
     WinDestroyMsgQueue(g_hmqCtrl);
     g_hmqCtrl = NULLHANDLE;
