Index: /trunk/include/VBox/HostServices/DragAndDropSvc.h
===================================================================
--- /trunk/include/VBox/HostServices/DragAndDropSvc.h	(revision 49890)
+++ /trunk/include/VBox/HostServices/DragAndDropSvc.h	(revision 49891)
@@ -4,5 +4,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -72,5 +72,9 @@
     HOST_DND_HG_EVT_DROPPED,
     HOST_DND_HG_EVT_CANCEL,
+    /** Gets the actual MIME data, based on
+     *  the format(s) specified by HOST_DND_HG_EVT_ENTER. */
     HOST_DND_HG_SND_DATA,
+    /** Sent when the actual buffer for HOST_DND_HG_SND_DATA
+     *  was too small. */
     HOST_DND_HG_SND_MORE_DATA,
     HOST_DND_HG_SND_DIR,
@@ -392,6 +396,7 @@
     uint32_t uPercentage;
     uint32_t uState;
+    int rc;
 } VBOXDNDCBHGEVTPROGRESSDATA;
-typedef VBOXDNDCBHGEVTPROGRESSDATA *PVBOXDNDCBHGEVTPROGRESSDATA ;
+typedef VBOXDNDCBHGEVTPROGRESSDATA *PVBOXDNDCBHGEVTPROGRESSDATA;
 
 typedef struct VBOXDNDCBGHACKPENDINGDATA
@@ -419,5 +424,5 @@
     /** Callback data header. */
     VBOXDNDCBHEADERDATA hdr;
-    int32_t  rc;
+    int32_t rc;
 } VBOXDNDCBEVTERRORDATA;
 typedef VBOXDNDCBEVTERRORDATA *PVBOXDNDCBEVTERRORDATA;
Index: /trunk/include/VBox/VBoxGuestLib.h
===================================================================
--- /trunk/include/VBox/VBoxGuestLib.h	(revision 49890)
+++ /trunk/include/VBox/VBoxGuestLib.h	(revision 49891)
@@ -78,5 +78,4 @@
 
 RT_C_DECLS_BEGIN
-
 
 /** @defgroup grp_guest_lib_r0     Ring-0 interface.
@@ -694,5 +693,5 @@
 {
     uint32_t uType;               /** The event type this struct contains */
-    uint32_t uScreenId;           /** Screen id this request belongs to */
+    uint32_t uScreenId;           /** Screen ID this request belongs to */
     char    *pszFormats;          /** Format list (\r\n separated) */
     uint32_t cbFormats;           /** Size of pszFormats (\0 included) */
@@ -715,18 +714,15 @@
 typedef VBGLR3DNDHGCMEVENT *PVBGLR3DNDHGCMEVENT;
 typedef const PVBGLR3DNDHGCMEVENT CPVBGLR3DNDHGCMEVENT;
-VBGLR3DECL(int)     VbglR3DnDInit(void);
-VBGLR3DECL(int)     VbglR3DnDTerm(void);
-
 VBGLR3DECL(int)     VbglR3DnDConnect(uint32_t *pu32ClientId);
 VBGLR3DECL(int)     VbglR3DnDDisconnect(uint32_t u32ClientId);
 
-VBGLR3DECL(int)     VbglR3DnDProcessNextMessage(CPVBGLR3DNDHGCMEVENT pEvent);
-
-VBGLR3DECL(int)     VbglR3DnDHGAcknowledgeOperation(uint32_t uAction);
-VBGLR3DECL(int)     VbglR3DnDHGRequestData(const char* pcszFormat);
+VBGLR3DECL(int)     VbglR3DnDProcessNextMessage(uint32_t u32ClientId, CPVBGLR3DNDHGCMEVENT pEvent);
+
+VBGLR3DECL(int)     VbglR3DnDHGAcknowledgeOperation(uint32_t u32ClientId, uint32_t uAction);
+VBGLR3DECL(int)     VbglR3DnDHGRequestData(uint32_t u32ClientId, const char* pcszFormat);
 #  ifdef VBOX_WITH_DRAG_AND_DROP_GH
-VBGLR3DECL(int)     VbglR3DnDGHAcknowledgePending(uint32_t uDefAction, uint32_t uAllActions, const char* pcszFormat);
-VBGLR3DECL(int)     VbglR3DnDGHSendData(void *pvData, uint32_t cbData);
-VBGLR3DECL(int)     VbglR3DnDGHErrorEvent(int rcOp);
+VBGLR3DECL(int)     VbglR3DnDGHAcknowledgePending(uint32_t u32ClientId, uint32_t uDefAction, uint32_t uAllActions, const char* pcszFormat);
+VBGLR3DECL(int)     VbglR3DnDGHSendData(uint32_t u32ClientId, void *pvData, uint32_t cbData);
+VBGLR3DECL(int)     VbglR3DnDGHErrorEvent(uint32_t u32ClientId, int rcOp);
 #  endif /* VBOX_WITH_DRAG_AND_DROP_GH */
 /** @} */
Index: /trunk/include/VBox/log.h
===================================================================
--- /trunk/include/VBox/log.h	(revision 49890)
+++ /trunk/include/VBox/log.h	(revision 49891)
@@ -222,4 +222,6 @@
     /** Guest control. */
     LOG_GROUP_GUEST_CONTROL,
+    /** Guest drag'n drop. */
+    LOG_GROUP_GUEST_DND,
     /** GUI group. */
     LOG_GROUP_GUI,
@@ -770,4 +772,5 @@
     "GMM",          \
     "GUEST_CONTROL", \
+    "GUEST_DND",    \
     "GUI",          \
     "GVMM",         \
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk	(revision 49890)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk	(revision 49891)
@@ -26,5 +26,7 @@
 endif
 VBoxTray_SDKS     = ReorderCompilerIncs $(VBOX_WINDDK_GST)
-VBoxTray_DEFS     = VBOX_WITH_HGCM LOG_TO_BACKDOOR
+VBoxTray_DEFS     = \
+	VBOX_WITH_HGCM \
+	VBOX_BUILD_TARGET=\"$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)\"
 VBoxTray_INCS     = ../include
 VBoxTray_SOURCES  = \
@@ -39,6 +41,16 @@
 	VBoxHelpers.cpp \
 	VBoxTray.rc
+ifdef VBOX_WITH_DRAG_AND_DROP
+ VBoxTray_DEFS     += \
+	VBOX_WITH_DRAG_AND_DROP \
+	$(if $(VBOX_WITH_DRAG_AND_DROP_GH),VBOX_WITH_DRAG_AND_DROP_GH,)
+ VBoxTray_SOURCES  += \
+	VBoxDnD.cpp \
+	VBoxDnDDataObject.cpp \
+	VBoxDnDEnumFormat.cpp \
+	VBoxDnDDropSource.cpp
+endif
 ifdef VBOX_WITH_GUEST_PROPS
- VBoxTray_DEFS     +=  _WIN32_IE=0x500 VBOX_WITH_GUEST_PROPS
+ VBoxTray_DEFS     += _WIN32_IE=0x500 VBOX_WITH_GUEST_PROPS
  VBoxTray_SOURCES  += \
 	VBoxHostVersion.cpp \
@@ -46,5 +58,5 @@
 endif
 ifdef VBOX_WITH_SHARED_FOLDERS
- VBoxTray_DEFS     +=  VBOX_WITH_SHARED_FOLDERS
+ VBoxTray_DEFS     += VBOX_WITH_SHARED_FOLDERS
  VBoxTray_SOURCES  += \
 	VBoxSharedFolders.cpp
@@ -57,5 +69,4 @@
         VBoxMMR.cpp
 endif
-
 ifdef VBOX_WITH_WDDM
  VBoxTray_DEFS   += VBOX_WITH_WDDM
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp	(revision 49890)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp	(revision 49891)
@@ -525,5 +525,7 @@
     }
 
+#ifndef DEBUG_andy
     Log(("VBoxTray: vboxClipboardProcessMsg returned with rc = %ld\n", rc));
+#endif
     return rc;
 }
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 49890)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 49891)
@@ -964,5 +964,7 @@
         else
         {
+#ifndef DEBUG_andy /* Too noisy for me. */
             Log(("VBoxTray: VBoxDisplayThread: error 0 from DeviceIoControl VBOXGUEST_IOCTL_WAITEVENT\n"));
+#endif
             /* sleep a bit to not eat too much CPU in case the above call always fails */
             if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 10) == WAIT_OBJECT_0)
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 49890)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 49891)
@@ -20,4 +20,12 @@
 *   Header Files                                                               *
 *******************************************************************************/
+#ifdef DEBUG
+# define LOG_ENABLED
+# define LOG_GROUP LOG_GROUP_DEFAULT
+#endif
+
+#include <package-generated.h>
+#include "product-generated.h"
+
 #include "VBoxTray.h"
 #include "VBoxTrayMsg.h"
@@ -30,4 +38,7 @@
 #include "VBoxHostVersion.h"
 #include "VBoxSharedFolders.h"
+#ifdef VBOX_WITH_DRAG_AND_DROP
+# include "VBoxDnD.h"
+#endif
 #include "VBoxIPC.h"
 #include "VBoxLA.h"
@@ -42,4 +53,8 @@
 #include <iprt/buildconfig.h>
 #include <iprt/ldr.h>
+#include <iprt/process.h>
+#include <iprt/system.h>
+#include <iprt/time.h>
+#include <VBox/log.h>
 
 /* Default desktop state tracking */
@@ -133,4 +148,8 @@
 DWORD                 gMajorVersion;
 
+static PRTLOGGER      g_pLoggerRelease = NULL;
+static uint32_t       g_cHistory = 10;                   /* Enable log rotation, 10 files. */
+static uint32_t       g_uHistoryFileTime = RT_SEC_1DAY;  /* Max 1 day per file. */
+static uint64_t       g_uHistoryFileSize = 100 * _1M;    /* Max 100MB per file. */
 
 /* The service table. */
@@ -195,4 +214,13 @@
         NULL /* pfnStop */,
         VBoxMMRDestroy
+    },
+#endif
+#ifdef VBOX_WITH_DRAG_AND_DROP
+    {
+        "Drag and Drop",
+        VBoxDnDInit,
+        VBoxDnDThread,
+        VBoxDnDStop,
+        VBoxDnDDestroy
     },
 #endif
@@ -475,4 +503,127 @@
         ghVBoxDriver = NULL;
     }
+}
+
+/**
+ * Release logger callback.
+ *
+ * @return  IPRT status code.
+ * @param   pLoggerRelease
+ * @param   enmPhase
+ * @param   pfnLog
+ */
+static void vboxTrayLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
+{
+    /* Some introductory information. */
+    static RTTIMESPEC s_TimeSpec;
+    char szTmp[256];
+    if (enmPhase == RTLOGPHASE_BEGIN)
+        RTTimeNow(&s_TimeSpec);
+    RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
+
+    switch (enmPhase)
+    {
+        case RTLOGPHASE_BEGIN:
+        {
+            pfnLog(pLoggerRelease,
+                   "VBoxTray %s r%s %s (%s %s) release log\n"
+                   "Log opened %s\n",
+                   RTBldCfgVersion(), RTBldCfgRevisionStr(), VBOX_BUILD_TARGET,
+                   __DATE__, __TIME__, szTmp);
+
+            int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
+            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
+                pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp);
+            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
+            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
+                pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp);
+            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
+            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
+                pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp);
+            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
+                pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp);
+
+            /* the package type is interesting for Linux distributions */
+            char szExecName[RTPATH_MAX];
+            char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
+            pfnLog(pLoggerRelease,
+                   "Executable: %s\n"
+                   "Process ID: %u\n"
+                   "Package type: %s"
+#ifdef VBOX_OSE
+                   " (OSE)"
+#endif
+                   "\n",
+                   pszExecName ? pszExecName : "unknown",
+                   RTProcSelf(),
+                   VBOX_PACKAGE_STRING);
+            break;
+        }
+
+        case RTLOGPHASE_PREROTATE:
+            pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp);
+            break;
+
+        case RTLOGPHASE_POSTROTATE:
+            pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp);
+            break;
+
+        case RTLOGPHASE_END:
+            pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp);
+            break;
+
+        default:
+            /* nothing */;
+    }
+}
+
+/**
+ * Creates the default release logger outputting to the specified file.
+ * Pass NULL for disabled logging.
+ *
+ * @return  IPRT status code.
+ * @param   pszLogFile              Filename for log output.  Optional.
+ */
+static int vboxTrayLogCreate(const char *pszLogFile)
+{
+    /* Create release logger (stdout + file). */
+    static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
+    RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG;
+#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
+    fFlags |= RTLOGFLAGS_USECRLF;
+#endif
+    char szError[RTPATH_MAX + 128] = "";
+    int rc = RTLogCreateEx(&g_pLoggerRelease, fFlags,
+#ifdef DEBUG
+                           "all.e.l.f",
+                           "VBOXTRAY_LOG",
+#else
+                           "all",
+                           "VBOXTRAY_RELEASE_LOG",
+#endif
+                           RT_ELEMENTS(s_apszGroups), s_apszGroups, RTLOGDEST_STDOUT,
+                           vboxTrayLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
+                           szError, sizeof(szError), pszLogFile);
+    if (RT_SUCCESS(rc))
+    {
+#ifdef DEBUG
+        RTLogSetDefaultInstance(g_pLoggerRelease);
+#else
+        /* Register this logger as the release logger. */
+        RTLogRelSetDefaultInstance(g_pLoggerRelease);
+#endif
+        /* Explicitly flush the log in case of VBOXTRAY_RELEASE_LOG=buffered. */
+        RTLogFlush(g_pLoggerRelease);
+    }
+    else
+        MessageBox(GetDesktopWindow(),
+                   szError, "VBoxTray - Logging Error", MB_OK | MB_ICONERROR);
+
+    return rc;
+}
+
+static void vboxTrayLogDestroy(void)
+{
+    RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
 }
 
@@ -802,5 +953,7 @@
                             while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                             {
+#ifndef DEBUG_andy
                                 Log(("VBoxTray: msg %p\n", msg.message));
+#endif
                                 if (msg.message == WM_QUIT)
                                 {
@@ -833,10 +986,11 @@
 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 {
-    /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
+    /* Note: Do not use a global namespace ("Global\\") for mutex name here,
+     * will blow up NT4 compatibility! */
     HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxTray");
     if (   hMutexAppRunning != NULL
         && GetLastError() == ERROR_ALREADY_EXISTS)
     {
-        /* Close the mutex for this application instance. */
+        /* VBoxTray already running? Bail out. */
         CloseHandle (hMutexAppRunning);
         hMutexAppRunning = NULL;
@@ -847,4 +1001,7 @@
 
     int rc = RTR3InitExeNoArguments(0);
+    if (RT_SUCCESS(rc))
+        rc = vboxTrayLogCreate(NULL /* pszLogFile */);
+
     if (RT_SUCCESS(rc))
     {
@@ -931,4 +1088,7 @@
 
     VbglR3Term();
+
+    vboxTrayLogDestroy();
+
     return RT_SUCCESS(rc) ? 0 : 1;
 }
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp	(revision 49890)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp	(revision 49891)
@@ -409,6 +409,7 @@
                 else
                 {
+#ifndef DEBUG_andy /* Too noisy for me. */
                     Log(("VBoxTray: VBoxVRDPThread: Error from DeviceIoControl VBOXGUEST_IOCTL_VMMREQUEST\n"));
-
+#endif
                     /* sleep a bit to not eat too much CPU in case the above call always fails */
                     if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 10) == WAIT_OBJECT_0)
@@ -422,6 +423,7 @@
         else
         {
+#ifndef DEBUG_andy
             Log(("VBoxTray: VBoxVRDPThread: Error from DeviceIoControl VBOXGUEST_IOCTL_WAITEVENT\n"));
-
+#endif
             /* sleep a bit to not eat too much CPU in case the above call always fails */
             if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 10) == WAIT_OBJECT_0)
Index: /trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp	(revision 49890)
+++ /trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp	(revision 49891)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -41,14 +41,4 @@
 #include "VBox/HostServices/DragAndDropSvc.h"
 
-#define VERBOSE 1
-
-#if defined(VERBOSE) && defined(DEBUG_poetzsch)
-# include <iprt/stream.h>
-# define DO(s) RTPrintf s
-#else
-# define DO(s) do {} while(0)
-//# define DO(s) Log s
-#endif
-
 /* Here all the communication with the host over HGCM is handled platform
  * neutral. Also the receiving of URIs content (directory trees and files) is
@@ -61,7 +51,4 @@
  */
 
-/* Not really used at the moment (only one client is possible): */
-uint32_t g_clientId = 0;
-
 /******************************************************************************
  *    Private internal functions                                              *
@@ -70,16 +57,23 @@
 static int vbglR3DnDCreateDropDir(char* pszDropDir, size_t cbSize)
 {
-    /* Validate input */
     AssertPtrReturn(pszDropDir, VERR_INVALID_POINTER);
     AssertReturn(cbSize,        VERR_INVALID_PARAMETER);
 
-    /* Get the users document directory (usually $HOME/Documents). */
-    int rc = RTPathUserDocuments(pszDropDir, cbSize);
+    /** @todo On Windows we also could use the registry to override
+     *        this path, on Posix a dotfile and/or a guest property
+     *        can be used. */
+
+    /* Get the users temp directory. Don't use the user's root directory (or
+     * something inside it) because we don't know for how long/if the data will
+     * be kept after the guest OS used it. */
+    int rc = RTPathTemp(pszDropDir, cbSize);
     if (RT_FAILURE(rc))
         return rc;
+
     /* Append our base drop directory. */
     rc = RTPathAppend(pszDropDir, cbSize, "VirtualBox Dropped Files");
     if (RT_FAILURE(rc))
         return rc;
+
     /* Create it when necessary. */
     if (!RTDirExists(pszDropDir))
@@ -89,4 +83,5 @@
             return rc;
     }
+
     /* The actually drop directory consist of the current time stamp and a
      * unique number when necessary. */
@@ -95,4 +90,14 @@
     if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime)))
         return VERR_BUFFER_OVERFLOW;
+#ifdef RT_OS_WINDOWS
+    /* Filter out characters not allowed on Windows platforms, put in by
+       RTTimeSpecToString(). */
+    /** @todo Use something like RTPathSanitize() when available. Later. */
+    RTUNICP aCpSet[] =
+        { ' ', ' ', '(', ')', '-', '.', '0', '9', 'A', 'Z', 'a', 'z', '_', '_',
+          0xa0, 0xd7af, '\0' };
+    RTStrPurgeComplementSet(pszTime, aCpSet, '_' /* Replacement */);
+#endif
+
     rc = RTPathAppend(pszDropDir, cbSize, pszTime);
     if (RT_FAILURE(rc))
@@ -105,9 +110,7 @@
 static int vbglR3DnDQueryNextHostMessageType(uint32_t uClientId, uint32_t *puMsg, uint32_t *pcParms, bool fWait)
 {
-    /* Validate input */
     AssertPtrReturn(puMsg,   VERR_INVALID_POINTER);
     AssertPtrReturn(pcParms, VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDNEXTMSGMSG Msg;
     RT_ZERO(Msg);
@@ -116,9 +119,9 @@
     Msg.hdr.u32Function = DragAndDropSvc::GUEST_DND_GET_NEXT_HOST_MSG;
     Msg.hdr.cParms      = 3;
-    /* Initialize parameter */
+
     Msg.msg.SetUInt32(0);
     Msg.num_parms.SetUInt32(0);
     Msg.block.SetUInt32(fWait);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -132,4 +135,5 @@
         }
     }
+
     return rc;
 }
@@ -146,5 +150,4 @@
                                            uint32_t *pcbFormatsRecv)
 {
-    /* Validate input */
     AssertPtrReturn(puScreenId,     VERR_INVALID_POINTER);
     AssertPtrReturn(puX,            VERR_INVALID_POINTER);
@@ -156,5 +159,4 @@
     AssertPtrReturn(pcbFormatsRecv, VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGACTIONMSG Msg;
     RT_ZERO(Msg);
@@ -162,5 +164,5 @@
     Msg.hdr.u32Function = uMsg;
     Msg.hdr.cParms      = 7;
-    /* Initialize parameter */
+
     Msg.uScreenId.SetUInt32(0);
     Msg.uX.SetUInt32(0);
@@ -170,5 +172,5 @@
     Msg.pvFormats.SetPtr(pszFormats, cbFormats);
     Msg.cFormats.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -188,4 +190,5 @@
         }
     }
+
     return rc;
 }
@@ -193,5 +196,4 @@
 static int vbglR3DnDHGProcessLeaveMessage(uint32_t uClientId)
 {
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGLEAVEMSG Msg;
     RT_ZERO(Msg);
@@ -199,8 +201,9 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_HG_EVT_LEAVE;
     Msg.hdr.cParms      = 0;
-    /* Do request */
-    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
-    if (RT_SUCCESS(rc))
-        rc = Msg.hdr.result;
+
+    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
+    if (RT_SUCCESS(rc))
+        rc = Msg.hdr.result;
+
     return rc;
 }
@@ -208,5 +211,4 @@
 static int vbglR3DnDHGProcessCancelMessage(uint32_t uClientId)
 {
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGCANCELMSG Msg;
     RT_ZERO(Msg);
@@ -214,8 +216,9 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_HG_EVT_CANCEL;
     Msg.hdr.cParms      = 0;
-    /* Do request */
-    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
-    if (RT_SUCCESS(rc))
-        rc = Msg.hdr.result;
+
+    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
+    if (RT_SUCCESS(rc))
+        rc = Msg.hdr.result;
+
     return rc;
 }
@@ -227,5 +230,4 @@
                                             uint32_t *pfMode)
 {
-    /* Validate input */
     AssertPtrReturn(pszDirname,     VERR_INVALID_POINTER);
     AssertReturn(cbDirname,         VERR_INVALID_PARAMETER);
@@ -233,5 +235,4 @@
     AssertPtrReturn(pfMode,         VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGSENDDIRMSG Msg;
     RT_ZERO(Msg);
@@ -239,9 +240,9 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_HG_SND_DIR;
     Msg.hdr.cParms      = 3;
-    /* Initialize parameter */
+
     Msg.pvName.SetPtr(pszDirname, cbDirname);
     Msg.cName.SetUInt32(0);
     Msg.fMode.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -257,4 +258,5 @@
         }
     }
+
     return rc;
 }
@@ -269,5 +271,4 @@
                                              uint32_t *pfMode)
 {
-    /* Validate input */
     AssertPtrReturn(pszFilename,     VERR_INVALID_POINTER);
     AssertReturn(cbFilename,         VERR_INVALID_PARAMETER);
@@ -278,5 +279,4 @@
     AssertPtrReturn(pfMode,          VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGSENDFILEMSG Msg;
     RT_ZERO(Msg);
@@ -284,5 +284,5 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_HG_SND_FILE;
     Msg.hdr.cParms      = 5;
-    /* Initialize parameter */
+
     Msg.pvName.SetPtr(pszFilename, cbFilename);
     Msg.cName.SetUInt32(0);
@@ -290,5 +290,5 @@
     Msg.cData.SetUInt32(0);
     Msg.fMode.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -306,4 +306,5 @@
         }
     }
+
     return rc;
 }
@@ -376,6 +377,5 @@
         uint32_t uNextMsg;
         uint32_t cNextParms;
-        rc = vbglR3DnDQueryNextHostMessageType(uClientId, &uNextMsg, &cNextParms, false);
-        DO(("%Rrc - %d\n", rc , uNextMsg));
+        rc = vbglR3DnDQueryNextHostMessageType(uClientId, &uNextMsg, &cNextParms, false /* fWait */);
         if (RT_SUCCESS(rc))
         {
@@ -392,5 +392,4 @@
                     if (RT_SUCCESS(rc))
                     {
-                        DO(("Got drop dir: %s - %o - %Rrc\n", pszPathname, fMode, rc));
                         char *pszNewDir = RTPathJoinA(pszDropDir, pszPathname);
                         rc = RTDirCreate(pszNewDir, (fMode & RTFS_UNIX_MASK) | RTFS_UNIX_IRWXU, 0);
@@ -415,6 +414,8 @@
                     {
                         char *pszNewFile = RTPathJoinA(pszDropDir, pszPathname);
-                        DO(("Got drop file: %s - %d - %o - %Rrc\n", pszPathname, cbDataRecv, fMode, rc));
                         RTFILE hFile;
+                        /** @todo r=andy Keep the file open and locked during the actual file transfer. Otherwise this will
+                         *               create all sorts of funny races because we don't know if the guest has
+                         *               modified the file in between the file data send calls. */
                         rc = RTFileOpen(&hFile, pszNewFile, RTFILE_O_WRITE | RTFILE_O_APPEND | RTFILE_O_DENY_ALL | RTFILE_O_OPEN_CREATE);
                         if (RT_SUCCESS(rc))
@@ -443,7 +444,10 @@
                     /* Break out of the loop. */
                 }
-                default: fLoop = false; break;
+                default:
+                    fLoop = false;
+                    break;
             }
-        } else
+        }
+        else
         {
             if (rc == VERR_NO_DATA)
@@ -451,7 +455,9 @@
             break;
         }
-    }while(fLoop);
+
+    } while (fLoop);
 
     RTMemFree(pvTmpData);
+
     /* Cleanup on failure or if the user has canceled. */
     if (RT_FAILURE(rc))
@@ -477,5 +483,4 @@
                                                  uint32_t *pcbDataRecv)
 {
-    /* Validate input */
     AssertPtrReturn(puScreenId,    VERR_INVALID_POINTER);
     AssertPtrReturn(pszFormat,     VERR_INVALID_POINTER);
@@ -486,5 +491,4 @@
     AssertPtrReturn(pcbDataRecv,   VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGSENDDATAMSG Msg;
     RT_ZERO(Msg);
@@ -492,5 +496,5 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_HG_SND_DATA;
     Msg.hdr.cParms      = 5;
-    /* Initialize parameter */
+
     Msg.uScreenId.SetUInt32(0);
     Msg.pvFormat.SetPtr(pszFormat, cbFormat);
@@ -498,5 +502,5 @@
     Msg.pvData.SetPtr(pvData, cbData);
     Msg.cData.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -515,4 +519,5 @@
         }
     }
+
     return rc;
 }
@@ -523,19 +528,17 @@
                                                      uint32_t *pcbDataRecv)
 {
-    /* Validate input */
     AssertPtrReturn(pvData,      VERR_INVALID_POINTER);
     AssertReturn(cbData,         VERR_INVALID_PARAMETER);
     AssertPtrReturn(pcbDataRecv, VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGSENDMOREDATAMSG Msg;
     RT_ZERO(Msg);
-    Msg.hdr.u32ClientID = g_clientId;
+    Msg.hdr.u32ClientID = uClientId;
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_HG_SND_MORE_DATA;
     Msg.hdr.cParms      = 2;
-    /* Initialize parameter */
+
     Msg.pvData.SetPtr(pvData, cbData);
     Msg.cData.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -554,12 +557,12 @@
 }
 
-static int vbglR3DnDHGProcessSendDataMessages(uint32_t  uClientId,
-                                              uint32_t *puScreenId,
-                                              char     *pszFormat,
-                                              uint32_t  cbFormat,
-                                              uint32_t *pcbFormatRecv,
-                                              void    **ppvData,
-                                              uint32_t  cbData,
-                                              size_t   *pcbDataRecv)
+static int vbglR3DnDHGProcessSendDataMessageLoop(uint32_t  uClientId,
+                                                 uint32_t *puScreenId,
+                                                 char     *pszFormat,
+                                                 uint32_t  cbFormat,
+                                                 uint32_t *pcbFormatRecv,
+                                                 void    **ppvData,
+                                                 uint32_t  cbData,
+                                                 size_t   *pcbDataRecv)
 {
     uint32_t cbDataRecv = 0;
@@ -572,6 +575,5 @@
                                                    cbData,
                                                    &cbDataRecv);
-
-    size_t cbAllDataRecv = cbDataRecv;
+    uint32_t cbAllDataRecv = cbDataRecv;
     while (rc == VERR_BUFFER_OVERFLOW)
     {
@@ -624,15 +626,17 @@
                                              size_t    *pcbDataRecv)
 {
-    int rc = vbglR3DnDHGProcessSendDataMessages(uClientId,
-                                                puScreenId,
-                                                pszFormat,
-                                                cbFormat,
-                                                pcbFormatRecv,
-                                                ppvData,
-                                                cbData,
-                                                pcbDataRecv);
-    if (RT_SUCCESS(rc))
-    {
-        /* Check if this is a uri-event */
+    int rc = vbglR3DnDHGProcessSendDataMessageLoop(uClientId,
+                                                   puScreenId,
+                                                   pszFormat,
+                                                   cbFormat,
+                                                   pcbFormatRecv,
+                                                   ppvData,
+                                                   cbData,
+                                                   pcbDataRecv);
+    if (RT_SUCCESS(rc))
+    {
+        /* Check if this is a uri-event. If so, let VbglR3 do all the actual
+         * data transfer + file /directory creation internally without letting
+         * the caller know. */
         if (RTStrNICmp(pszFormat, "text/uri-list", *pcbFormatRecv) == 0)
             rc = vbglR3DnDHGProcessURIMessages(uClientId,
@@ -645,4 +649,5 @@
                                                pcbDataRecv);
     }
+
     return rc;
 }
@@ -651,8 +656,6 @@
                                                    uint32_t *puScreenId)
 {
-    /* Validate input */
     AssertPtrReturn(puScreenId, VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDGHREQPENDINGMSG Msg;
     RT_ZERO(Msg);
@@ -660,7 +663,7 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_GH_REQ_PENDING;
     Msg.hdr.cParms      = 1;
-    /* Initialize parameter */
+
     Msg.uScreenId.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -673,4 +676,5 @@
         }
     }
+
     return rc;
 }
@@ -682,5 +686,4 @@
                                             uint32_t *puAction)
 {
-    /* Validate input */
     AssertPtrReturn(pszFormat,     VERR_INVALID_POINTER);
     AssertReturn(cbFormat,         VERR_INVALID_PARAMETER);
@@ -688,5 +691,4 @@
     AssertPtrReturn(puAction,      VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDGHDROPPEDMSG Msg;
     RT_ZERO(Msg);
@@ -694,9 +696,9 @@
     Msg.hdr.u32Function = DragAndDropSvc::HOST_DND_GH_EVT_DROPPED;
     Msg.hdr.cParms      = 3;
-    /* Initialize parameter */
+
     Msg.pvFormat.SetPtr(pszFormat, cbFormat);
     Msg.cFormat.SetUInt32(0);
     Msg.uAction.SetUInt32(0);
-    /* Do request */
+
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     if (RT_SUCCESS(rc))
@@ -712,4 +714,5 @@
         }
     }
+
     return rc;
 }
@@ -719,31 +722,6 @@
  ******************************************************************************/
 
-/**
- * Initialize Drag & Drop.
- *
- * This will enable the Drag & Drop events.
- *
- * @returns VBox status code.
- */
-VBGLR3DECL(int) VbglR3DnDInit(void)
-{
-    return VbglR3DnDConnect(&g_clientId);
-}
-
-/**
- * Terminate Drag and Drop.
- *
- * This will Drag and Drop events.
- *
- * @returns VBox status.
- */
-VBGLR3DECL(int) VbglR3DnDTerm(void)
-{
-    return VbglR3DnDDisconnect(g_clientId);
-}
-
 VBGLR3DECL(int) VbglR3DnDConnect(uint32_t *pu32ClientId)
 {
-    /* Validate input */
     AssertPtrReturn(pu32ClientId, VERR_INVALID_POINTER);
 
@@ -770,18 +748,18 @@
 VBGLR3DECL(int) VbglR3DnDDisconnect(uint32_t u32ClientId)
 {
-    /* Initialize header */
     VBoxGuestHGCMDisconnectInfo Info;
     Info.result      = VERR_WRONG_ORDER;
     Info.u32ClientID = u32ClientId;
+
     /* Do request */
     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
     if (RT_SUCCESS(rc))
         rc = Info.result;
-    return rc;
-}
-
-VBGLR3DECL(int) VbglR3DnDProcessNextMessage(CPVBGLR3DNDHGCMEVENT pEvent)
-{
-    /* Validate input */
+
+    return rc;
+}
+
+VBGLR3DECL(int) VbglR3DnDProcessNextMessage(uint32_t u32ClientId, CPVBGLR3DNDHGCMEVENT pEvent)
+{
     AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
 
@@ -789,9 +767,9 @@
     uint32_t       uNumParms  = 0;
     const uint32_t ccbFormats = _64K;
-    const uint32_t ccbData    = _1M;
-    int rc = vbglR3DnDQueryNextHostMessageType(g_clientId, &uMsg, &uNumParms, true);
-    if (RT_SUCCESS(rc))
-    {
-        DO(("Got message %d\n", uMsg));
+    const uint32_t ccbData    = _64K;
+    int rc = vbglR3DnDQueryNextHostMessageType(u32ClientId, &uMsg, &uNumParms,
+                                               true /* fWait */);
+    if (RT_SUCCESS(rc))
+    {
         switch(uMsg)
         {
@@ -803,15 +781,17 @@
                 pEvent->pszFormats = static_cast<char*>(RTMemAlloc(ccbFormats));
                 if (!pEvent->pszFormats)
-                    return VERR_NO_MEMORY;
-                rc = vbglR3DnDHGProcessActionMessage(g_clientId,
-                                                     uMsg,
-                                                     &pEvent->uScreenId,
-                                                     &pEvent->u.a.uXpos,
-                                                     &pEvent->u.a.uYpos,
-                                                     &pEvent->u.a.uDefAction,
-                                                     &pEvent->u.a.uAllActions,
-                                                     pEvent->pszFormats,
-                                                     ccbFormats,
-                                                     &pEvent->cbFormats);
+                    rc = VERR_NO_MEMORY;
+
+                if (RT_SUCCESS(rc))
+                    rc = vbglR3DnDHGProcessActionMessage(u32ClientId,
+                                                         uMsg,
+                                                         &pEvent->uScreenId,
+                                                         &pEvent->u.a.uXpos,
+                                                         &pEvent->u.a.uYpos,
+                                                         &pEvent->u.a.uDefAction,
+                                                         &pEvent->u.a.uAllActions,
+                                                         pEvent->pszFormats,
+                                                         ccbFormats,
+                                                         &pEvent->cbFormats);
                 break;
             }
@@ -819,5 +799,5 @@
             {
                 pEvent->uType = uMsg;
-                rc = vbglR3DnDHGProcessLeaveMessage(g_clientId);
+                rc = vbglR3DnDHGProcessLeaveMessage(u32ClientId);
                 break;
             }
@@ -827,20 +807,32 @@
                 pEvent->pszFormats = static_cast<char*>(RTMemAlloc(ccbFormats));
                 if (!pEvent->pszFormats)
-                    return VERR_NO_MEMORY;
-                pEvent->u.b.pvData = RTMemAlloc(ccbData);
-                if (!pEvent->u.b.pvData)
+                    rc = VERR_NO_MEMORY;
+
+                if (RT_SUCCESS(rc))
                 {
-                    RTMemFree(pEvent->pszFormats);
-                    pEvent->pszFormats = NULL;
-                    return VERR_NO_MEMORY;
+                    pEvent->u.b.pvData = RTMemAlloc(ccbData);
+                    if (!pEvent->u.b.pvData)
+                    {
+                        RTMemFree(pEvent->pszFormats);
+                        pEvent->pszFormats = NULL;
+                        rc = VERR_NO_MEMORY;
+                    }
                 }
-                rc = vbglR3DnDHGProcessSendDataMessage(g_clientId,
-                                                       &pEvent->uScreenId,
-                                                       pEvent->pszFormats,
-                                                       ccbFormats,
-                                                       &pEvent->cbFormats,
-                                                       &pEvent->u.b.pvData,
-                                                       ccbData,
-                                                       &pEvent->u.b.cbData);
+
+                if (RT_SUCCESS(rc))
+                    rc = vbglR3DnDHGProcessSendDataMessage(u32ClientId,
+                                                           &pEvent->uScreenId,
+                                                           pEvent->pszFormats,
+                                                           ccbFormats,
+                                                           &pEvent->cbFormats,
+                                                           &pEvent->u.b.pvData,
+                                                           ccbData,
+                                                           &pEvent->u.b.cbData);
+                break;
+            }
+            case DragAndDropSvc::HOST_DND_HG_EVT_CANCEL:
+            {
+                pEvent->uType = uMsg;
+                rc = vbglR3DnDHGProcessCancelMessage(u32ClientId);
                 break;
             }
@@ -849,5 +841,5 @@
             {
                 pEvent->uType = uMsg;
-                rc = vbglR3DnDGHProcessRequestPendingMessage(g_clientId,
+                rc = vbglR3DnDGHProcessRequestPendingMessage(u32ClientId,
                                                              &pEvent->uScreenId);
                 break;
@@ -858,35 +850,31 @@
                 pEvent->pszFormats = static_cast<char*>(RTMemAlloc(ccbFormats));
                 if (!pEvent->pszFormats)
-                    return VERR_NO_MEMORY;
-                rc = vbglR3DnDGHProcessDroppedMessage(g_clientId,
-                                                      pEvent->pszFormats,
-                                                      ccbFormats,
-                                                      &pEvent->cbFormats,
-                                                      &pEvent->u.a.uDefAction);
+                    rc = VERR_NO_MEMORY;
+
+                if (RT_SUCCESS(rc))
+                    rc = vbglR3DnDGHProcessDroppedMessage(u32ClientId,
+                                                          pEvent->pszFormats,
+                                                          ccbFormats,
+                                                          &pEvent->cbFormats,
+                                                          &pEvent->u.a.uDefAction);
                 break;
             }
 #endif /* VBOX_WITH_DRAG_AND_DROP_GH */
-            case DragAndDropSvc::HOST_DND_HG_EVT_CANCEL:
-            {
-                pEvent->uType = uMsg;
-                rc = vbglR3DnDHGProcessCancelMessage(g_clientId);
-                if (RT_SUCCESS(rc))
-                    rc = VERR_CANCELLED;
+            default:
+                AssertMsgFailedReturn(("Message %u isn't expected in this context", uMsg),
+                                      VERR_INVALID_PARAMETER);
                 break;
-            }
-            default: AssertMsgFailedReturn(("Message %u isn't expected in this context", uMsg), VERR_INVALID_PARAMETER); break;
-        }
-    }
-    return rc;
-}
-
-VBGLR3DECL(int) VbglR3DnDHGAcknowledgeOperation(uint32_t uAction)
-{
-    DO(("ACK: %u\n", uAction));
-    /* Initialize header */
+        }
+    }
+
+    return rc;
+}
+
+VBGLR3DECL(int) VbglR3DnDHGAcknowledgeOperation(uint32_t u32ClientId, uint32_t uAction)
+{
     DragAndDropSvc::VBOXDNDHGACKOPMSG Msg;
     RT_ZERO(Msg);
     Msg.hdr.result      = VERR_WRONG_ORDER;
-    Msg.hdr.u32ClientID = g_clientId;
+    Msg.hdr.u32ClientID = u32ClientId;
     Msg.hdr.u32Function = DragAndDropSvc::GUEST_DND_HG_ACK_OP;
     Msg.hdr.cParms      = 1;
@@ -897,18 +885,16 @@
     if (RT_SUCCESS(rc))
         rc = Msg.hdr.result;
-    return rc;
-}
-
-VBGLR3DECL(int) VbglR3DnDHGRequestData(const char* pcszFormat)
-{
-    DO(("DATA_REQ: '%s'\n", pcszFormat));
-    /* Validate input */
+
+    return rc;
+}
+
+VBGLR3DECL(int) VbglR3DnDHGRequestData(uint32_t u32ClientId, const char* pcszFormat)
+{
     AssertPtrReturn(pcszFormat, VERR_INVALID_PARAMETER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDHGREQDATAMSG Msg;
     RT_ZERO(Msg);
     Msg.hdr.result      = VERR_WRONG_ORDER;
-    Msg.hdr.u32ClientID = g_clientId;
+    Msg.hdr.u32ClientID = u32ClientId;
     Msg.hdr.u32Function = DragAndDropSvc::GUEST_DND_HG_REQ_DATA;
     Msg.hdr.cParms      = 1;
@@ -918,18 +904,18 @@
     if (RT_SUCCESS(rc))
         rc = Msg.hdr.result;
-    return rc;
-}
-
-VBGLR3DECL(int) VbglR3DnDGHAcknowledgePending(uint32_t uDefAction, uint32_t uAllActions, const char* pcszFormat)
-{
-    DO(("PEND: %u: %u (%s)\n", uDefAction, uAllActions, pcszFormat));
-    /* Validate input */
+
+    return rc;
+}
+
+VBGLR3DECL(int) VbglR3DnDGHAcknowledgePending(uint32_t u32ClientId,
+                                              uint32_t uDefAction, uint32_t uAllActions,
+                                              const char* pcszFormat)
+{
     AssertPtrReturn(pcszFormat, VERR_INVALID_POINTER);
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDGHACKPENDINGMSG Msg;
     RT_ZERO(Msg);
     Msg.hdr.result      = VERR_WRONG_ORDER;
-    Msg.hdr.u32ClientID = g_clientId;
+    Msg.hdr.u32ClientID = u32ClientId;
     Msg.hdr.u32Function = DragAndDropSvc::GUEST_DND_GH_ACK_PENDING;
     Msg.hdr.cParms      = 3;
@@ -942,11 +928,10 @@
     if (RT_SUCCESS(rc))
         rc = Msg.hdr.result;
-    return rc;
-}
-
-VBGLR3DECL(int) VbglR3DnDGHSendData(void *pvData, uint32_t cbData)
-{
-    DO(("DATA: %x (%u)\n", pvData, cbData));
-    /* Validate input */
+
+    return rc;
+}
+
+VBGLR3DECL(int) VbglR3DnDGHSendData(uint32_t u32ClientId, void *pvData, uint32_t cbData)
+{
     AssertPtrReturn(pvData, VERR_INVALID_POINTER);
     AssertReturn(cbData,    VERR_INVALID_PARAMETER);
@@ -962,9 +947,8 @@
      */
 
-    /* Initialize header */
     DragAndDropSvc::VBOXDNDGHSENDDATAMSG Msg;
     RT_ZERO(Msg);
     Msg.hdr.result      = VERR_WRONG_ORDER;
-    Msg.hdr.u32ClientID = g_clientId;
+    Msg.hdr.u32ClientID = u32ClientId;
     Msg.hdr.u32Function = DragAndDropSvc::GUEST_DND_GH_SND_DATA;
     Msg.hdr.cParms      = 2;
@@ -992,16 +976,14 @@
 //        RTThreadSleep(500);
     }
-    return rc;
-}
-
-VBGLR3DECL(int) VbglR3DnDGHErrorEvent(int rcOp)
-{
-    DO(("GH_ERROR\n"));
-
-    /* Initialize header */
+
+    return rc;
+}
+
+VBGLR3DECL(int) VbglR3DnDGHErrorEvent(uint32_t u32ClientId, int rcOp)
+{
     DragAndDropSvc::VBOXDNDGHEVTERRORMSG Msg;
     RT_ZERO(Msg);
     Msg.hdr.result      = VERR_WRONG_ORDER;
-    Msg.hdr.u32ClientID = g_clientId;
+    Msg.hdr.u32ClientID = u32ClientId;
     Msg.hdr.u32Function = DragAndDropSvc::GUEST_DND_GH_EVT_ERROR;
     Msg.hdr.cParms      = 1;
@@ -1012,4 +994,5 @@
     if (RT_SUCCESS(rc))
         rc = Msg.hdr.result;
-    return rc;
-}
+
+    return rc;
+}
Index: /trunk/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp
===================================================================
--- /trunk/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp	(revision 49890)
+++ /trunk/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp	(revision 49891)
@@ -4,5 +4,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -55,5 +55,5 @@
  * G->H:
  * This is a lot more trickery than H->G. When a pending event from HGCM
- * arrives, we asks if there is currently an owner of the XdndSelection
+ * arrives, we ask if there currently is an owner of the XdndSelection
  * property. If so, our proxy window is shown (1x1, but without backing store)
  * and some mouse event is triggered. This should be followed by an XdndEnter
@@ -65,5 +65,5 @@
  * Todo:
  * - this isn't finished, yet. Currently the mouse isn't correctly released
- * in the guest (both, when the drop was successfully or canceled).
+ *   in the guest (both, when the drop was successfully or canceled).
  * - cancel (e.g. with the ESC key) doesn't work
  *
@@ -74,14 +74,4 @@
  * - really check for the Xdnd version and the supported features
  */
-
-#define VERBOSE 1
-
-#if defined(VERBOSE) && defined(DEBUG_poetzsch)
-# include <iprt/stream.h>
-# define DO(s) RTPrintf s
-#else
-# define DO(s) do {} while (0)
-//# define DO(s) Log s
-#endif
 
 #define VBOX_XDND_VERSION    (4)
@@ -154,11 +144,12 @@
 public:
 
-    static xHelpers *instance(Display *pDisplay = 0)
+    static xHelpers *getInstance(Display *pDisplay = 0)
     {
         if (!m_pInstance)
         {
-            AssertPtrReturn(pDisplay, 0);
+            AssertPtrReturn(pDisplay, NULL);
             m_pInstance = new xHelpers(pDisplay);
         }
+
         return m_pInstance;
     }
@@ -211,5 +202,5 @@
 
 /* Some xHelpers convenience defines. */
-#define gX11 xHelpers::instance()
+#define gX11 xHelpers::getInstance()
 #define xAtom(xa) gX11->xAtom((xa))
 #define xAtomToString(xa) gX11->xAtomToString((xa))
@@ -285,22 +276,22 @@
 
 /* Todo: make this iterative */
-Window xHelpers::applicationWindowBelowCursor(Window parentWin) const
+Window xHelpers::applicationWindowBelowCursor(Window wndParent) const
 {
     /* No parent, nothing to do. */
-    if(parentWin == 0)
+    if(wndParent == 0)
         return 0;
 
-    Window appWin = 0;
+    Window wndApp = 0;
     int cProps = -1;
     /* Fetch all x11 window properties of the parent window. */
-    Atom *pProps = XListProperties(m_pDisplay, parentWin, &cProps);
+    Atom *pProps = XListProperties(m_pDisplay, wndParent, &cProps);
     if (cProps > 0)
     {
         /* We check the window for the WM_STATE property. */
-        for(int i = 0; i < cProps; ++i)
-            if(pProps[i] == xAtom(XA_WM_STATE))
+        for (int i = 0; i < cProps; ++i)
+            if (pProps[i] == xAtom(XA_WM_STATE))
             {
                 /* Found it. */
-                appWin = parentWin;
+                wndApp = wndParent;
                 break;
             }
@@ -309,17 +300,17 @@
     }
 
-    if (!appWin)
-    {
-        Window childWin, wtmp;
+    if (!wndApp)
+    {
+        Window wndChild, wndTemp;
         int tmp;
         unsigned int utmp;
         /* Query the next child window of the parent window at the current
          * mouse position. */
-        XQueryPointer(m_pDisplay, parentWin, &wtmp, &childWin, &tmp, &tmp, &tmp, &tmp, &utmp);
+        XQueryPointer(m_pDisplay, wndParent, &wndTemp, &wndChild, &tmp, &tmp, &tmp, &tmp, &utmp);
         /* Recursive call our self to dive into the child tree. */
-        appWin = applicationWindowBelowCursor(childWin);
-    }
-
-    return appWin;
+        wndApp = applicationWindowBelowCursor(wndChild);
+    }
+
+    return wndApp;
 }
 
@@ -390,11 +381,12 @@
 
     /* Member vars */
+    uint32_t            m_uClientID;
     DragAndDropService *m_pParent;
     Display            *m_pDisplay;
     int                 m_screenId;
     Screen             *m_pScreen;
-    Window              m_rootWin;
-    Window              m_proxyWin;
-    Window              m_curWin;
+    Window              m_wndRoot;
+    Window              m_wndProxy;
+    Window              m_wndCur;
     long                m_curVer;
     RTCList<Atom>       m_formats;
@@ -418,5 +410,5 @@
 {
 public:
-    DragAndDropService()
+    DragAndDropService(void)
       : m_pDisplay(0)
       , m_hHGCMThread(NIL_RTTHREAD)
@@ -433,14 +425,13 @@
     virtual int run(bool fDaemonised = false);
 
-    virtual void cleanup()
+    virtual void cleanup(void)
     {
         /* Cleanup */
         x11DragAndDropTerm();
-        VbglR3DnDTerm();
     };
 
 private:
-    int x11DragAndDropInit();
-    int x11DragAndDropTerm();
+    int x11DragAndDropInit(void);
+    int x11DragAndDropTerm(void);
     static int hgcmEventThread(RTTHREAD hThread, void *pvUser);
     static int x11EventThread(RTTHREAD hThread, void *pvUser);
@@ -451,8 +442,8 @@
      * Unfortunately this doesn't work exactly with the events we need. So we
      * use this predicate method below and XCheckIfEvent. */
-    static Bool isDnDRespondEvent(Display * /* pDisplay */, XEvent *pEvent, char *pUser)
+    static bool isDnDRespondEvent(Display * /* pDisplay */, XEvent *pEvent, char *pUser)
     {
         if (!pEvent)
-            return False;
+            return false;
         if (   pEvent->type == SelectionClear
             || pEvent->type == ClientMessage
@@ -463,6 +454,6 @@
 //            || (   pEvent->type == SelectionRequest
 //                && reinterpret_cast<XSelectionRequestEvent*>(pEvent)->requestor == reinterpret_cast<Window>(pUser)))
-            return True;
-        return False;
+            return true;
+        return false;
     }
 
@@ -487,10 +478,11 @@
 
 DragInstance::DragInstance(Display *pDisplay, DragAndDropService *pParent)
-  : m_pParent(pParent)
+  : m_uClientID(0)
+  , m_pParent(pParent)
   , m_pDisplay(pDisplay)
   , m_pScreen(0)
-  , m_rootWin(0)
-  , m_proxyWin(0)
-  , m_curWin(0)
+  , m_wndRoot(0)
+  , m_wndProxy(0)
+  , m_wndCur(0)
   , m_curVer(-1)
   , m_mode(Unknown)
@@ -500,17 +492,24 @@
 }
 
-void DragInstance::uninit()
+void DragInstance::uninit(void)
 {
     reset();
-    if (m_proxyWin != 0)
-        XDestroyWindow(m_pDisplay, m_proxyWin);
+    if (m_wndProxy != 0)
+        XDestroyWindow(m_pDisplay, m_wndProxy);
+
+    if (m_uClientID) 
+    {
+        VbglR3DnDDisconnect(m_uClientID);
+        m_uClientID = 0;
+    }
+
     m_state    = Uninitialized;
     m_screenId = -1;
     m_pScreen  = 0;
-    m_rootWin  = 0;
-    m_proxyWin = 0;
-}
-
-void DragInstance::reset()
+    m_wndRoot  = 0;
+    m_wndProxy = 0;
+}
+
+void DragInstance::reset(void)
 {
     /* Hide the proxy win. */
@@ -518,12 +517,12 @@
     /* If we are currently the Xdnd selection owner, clear that. */
     Window w = XGetSelectionOwner(m_pDisplay, xAtom(XA_XdndSelection));
-    if (w == m_proxyWin)
+    if (w == m_wndProxy)
         XSetSelectionOwner(m_pDisplay, xAtom(XA_XdndSelection), None, CurrentTime);
     /* Clear any other DnD specific data on the proxy win. */
-    clearFormatsWindowProperty(m_proxyWin);
-    clearActionsWindowProperty(m_proxyWin);
+    clearFormatsWindowProperty(m_wndProxy);
+    clearActionsWindowProperty(m_wndProxy);
     /* Reset the internal state. */
     m_formats.clear();
-    m_curWin = 0;
+    m_wndCur = 0;
     m_curVer = -1;
     m_state  = Initialized;
@@ -546,12 +545,20 @@
 int DragInstance::init(uint32_t u32ScreenId)
 {
-    int rc = VINF_SUCCESS;
+    int rc;
+
     do
     {
         uninit();
-        /* Enough screens configured in the x11 server? */
+
+        rc = VbglR3DnDConnect(&m_uClientID);
+        if (RT_FAILURE(rc))
+            break;
+
+        /*
+         * Enough screens configured in the x11 server?
+         */
         if ((int)u32ScreenId > ScreenCount(m_pDisplay))
         {
-            rc = VERR_GENERAL_FAILURE;
+            rc = VERR_INVALID_PARAMETER;
             break;
         }
@@ -565,38 +572,48 @@
         m_screenId = u32ScreenId;
         /* Now query the corresponding root window of this screen. */
-        m_rootWin = RootWindow(m_pDisplay, m_screenId);
-        if (!m_rootWin)
+        m_wndRoot = RootWindow(m_pDisplay, m_screenId);
+        if (!m_wndRoot)
         {
             rc = VERR_GENERAL_FAILURE;
             break;
         }
-        /* Create an invisible window which will act as proxy for the DnD
+
+        /*
+         * Create an invisible window which will act as proxy for the DnD
          * operation. This window will be used for both the GH and HG
-         * direction. */
+         * direction.
+         */
         XSetWindowAttributes attr;
         RT_ZERO(attr);
         attr.do_not_propagate_mask = 0;
         attr.override_redirect     = True;
-//        attr.background_pixel      = WhitePixel(m_pDisplay, m_screenId);
-        m_proxyWin = XCreateWindow(m_pDisplay, m_rootWin, 0, 0, 1, 1, 0,
+#if 0
+        attr.background_pixel      = WhitePixel(m_pDisplay, m_screenId);
+#endif
+        m_wndProxy = XCreateWindow(m_pDisplay, m_wndRoot, 0, 0, 1, 1, 0,
                                    CopyFromParent, InputOnly, CopyFromParent,
                                    CWOverrideRedirect | CWDontPropagate,
                                    &attr);
-
-//        m_proxyWin = XCreateSimpleWindow(m_pDisplay, m_rootWin, 0, 0, 50, 50, 0, WhitePixel(m_pDisplay, m_screenId), WhitePixel(m_pDisplay, m_screenId));
-
-        if (!m_proxyWin)
+#ifdef DEBUG_andy
+        m_wndProxy = XCreateSimpleWindow(m_pDisplay, m_wndRoot, 0, 0, 50, 50, 0,
+                                         WhitePixel(m_pDisplay, m_screenId),
+                                         WhitePixel(m_pDisplay, m_screenId));
+#endif
+        if (!m_wndProxy)
         {
             rc = VERR_GENERAL_FAILURE;
             break;
         }
+
         /* Make the new window Xdnd aware. */
         Atom ver = VBOX_XDND_VERSION;
-        XChangeProperty(m_pDisplay, m_proxyWin, xAtom(XA_XdndAware), XA_ATOM, 32, PropModeReplace,
+        XChangeProperty(m_pDisplay, m_wndProxy, xAtom(XA_XdndAware), XA_ATOM, 32, PropModeReplace,
                         reinterpret_cast<unsigned char*>(&ver), 1);
     } while (0);
 
-    m_state = Initialized;
-
+    if (RT_SUCCESS(rc))
+        m_state = Initialized;
+
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -606,15 +623,14 @@
  */
 
-int DragInstance::hgEnter(const RTCList<RTCString> &formats, uint32_t actions)
-{
-    int rc = VINF_SUCCESS;
-
+int DragInstance::hgEnter(const RTCList<RTCString> &formats, uint32_t uActions)
+{
     reset();
-    DO(("DnD_ENTR: formats=%u: ", formats.size()));
-#if defined(VERBOSE) && defined(DEBUG_poetzsch)
+
+#ifdef DEBUG
+    LogFlowThisFunc(("uActions=0x%x, lstFormats=%zu: ", uActions, formats.size()));
     for (size_t i = 0; i < formats.size(); ++i)
-        DO(("'%s' ", formats.at(i).c_str()));
-#endif /* DEBUG */
-    DO(("\n"));
+        LogFlow(("'%s' ", formats.at(i).c_str()));
+    LogFlow(("\n"));
+#endif
 
     m_formats = toAtomList(formats);
@@ -622,21 +638,22 @@
     /* If we have more than 3 formats we have to use the type list extension. */
     if (m_formats.size() > 3)
-        setFormatsWindowProperty(m_proxyWin, xAtom(XA_XdndTypeList));
+        setFormatsWindowProperty(m_wndProxy, xAtom(XA_XdndTypeList));
 
     /* Announce the possible actions */
-    setActionsWindowProperty(m_proxyWin, toX11Actions(actions));
+    setActionsWindowProperty(m_wndProxy, toX11Actions(uActions));
 
     /* Set the DnD selection owner to our window. */
-    XSetSelectionOwner(m_pDisplay, xAtom(XA_XdndSelection), m_proxyWin, CurrentTime);
+    XSetSelectionOwner(m_pDisplay, xAtom(XA_XdndSelection), m_wndProxy, CurrentTime);
 
     m_mode  = HG;
     m_state = Dragging;
 
-    return rc;
-}
-
-int DragInstance::hgMove(uint32_t u32xPos, uint32_t u32yPos, uint32_t action)
-{
-    DO(("DnD_MOVE: "));
+    return VINF_SUCCESS;
+}
+
+int DragInstance::hgMove(uint32_t u32xPos, uint32_t u32yPos, uint32_t uAction)
+{
+    LogFlowThisFunc(("u32xPos=%RU32, u32yPos=%RU32, uAction=%RU32\n",
+                     u32xPos, u32yPos, uAction));
 
     if (   m_mode  != HG
@@ -650,10 +667,9 @@
     moveCursor(u32xPos, u32yPos);
 
-    Window newWin = None; /* Default to _no_ window below the cursor. */
-    long   newVer = -1;   /* This means the current window is _not_ XdndAware. */
+    long newVer = -1; /* This means the current window is _not_ XdndAware. */
 
     /* Search for the application window below the cursor. */
-    newWin = gX11->applicationWindowBelowCursor(m_rootWin);
-    if (newWin != None)
+    Window wndCursor = gX11->applicationWindowBelowCursor(m_wndRoot);
+    if (wndCursor != None)
     {
         /* Temp stuff for the XGetWindowProperty call. */
@@ -662,17 +678,20 @@
         unsigned long cItems, cbRemaining;
         unsigned char *pcData = NULL;
+
         /* Query the XdndAware property from the window. We are interested in
          * the version and if it is XdndAware at all. */
-        xrc = XGetWindowProperty(m_pDisplay, newWin, xAtom(XA_XdndAware), 0, 2, False, AnyPropertyType, &atmp, &fmt, &cItems, &cbRemaining, &pcData);
+        xrc = XGetWindowProperty(m_pDisplay, wndCursor, xAtom(XA_XdndAware),
+                                 0, 2, False, AnyPropertyType,
+                                 &atmp, &fmt, &cItems, &cbRemaining, &pcData);
         if (RT_UNLIKELY(xrc != Success))
-            DO(("DnD_MOVE: error in getting the window property (%s)\n", gX11->xErrorToString(xrc).c_str()));
+            LogFlowThisFunc(("Error in getting the window property: %s\n", gX11->xErrorToString(xrc).c_str()));
         else
         {
             if (RT_UNLIKELY(pcData == NULL || fmt != 32 || cItems != 1))
-                DO(("Prop=error[data=%#x,fmt=%u,items=%u] ", pcData, fmt, cItems));
+                LogFlowThisFunc(("Wrong properties pcData=%#x, iFmt=%u, cItems=%u\n", pcData, fmt, cItems));
             else
             {
                 newVer = reinterpret_cast<long*>(pcData)[0];
-                DO(("XdndAware=%u ", newVer));
+                LogFlowThisFunc(("wndCursor=%#x, XdndAware=%u\n", newVer));
             }
             XFree(pcData);
@@ -680,41 +699,47 @@
     }
 
-    if (newWin != m_curWin && m_curVer != -1)
-    {
-        DO(("leave=%#x ", m_curWin));
+    /*
+     * Is the window under the cursor another one than our current one?
+     */
+    if (wndCursor != m_wndCur && m_curVer != -1)
+    {
+        LogFlowThisFunc(("Leaving window=%#x\n", m_wndCur));
 
         /* We left the current XdndAware window. Announce this to the window. */
-
         XClientMessageEvent m;
         RT_ZERO(m);
         m.type         = ClientMessage;
         m.display      = m_pDisplay;
-        m.window       = m_curWin;
+        m.window       = m_wndCur;
         m.message_type = xAtom(XA_XdndLeave);
         m.format       = 32;
-        m.data.l[0]    = m_proxyWin;
-
-        xrc = XSendEvent(m_pDisplay, m_curWin, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
+        m.data.l[0]    = m_wndProxy;
+
+        xrc = XSendEvent(m_pDisplay, m_wndCur, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
         if (RT_UNLIKELY(xrc == 0))
-            DO(("DnD_MOVE: error sending xevent\n"));
-    }
-
-    if (newWin != m_curWin && newVer != -1)
-    {
-        DO(("enter=%#x ", newWin));
-
-        /* We enter a new window. Announce the XdndEnter event to the new
+            LogFlowThisFunc(("Error sending XA_XdndLeave to old window=%#x\n", m_wndCur));
+    }
+
+    /*
+     * Do we have a new window which now is under the cursor?
+     */
+    if (wndCursor != m_wndCur && newVer != -1)
+    {
+        LogFlowThisFunc(("Entering window=%#x\n", wndCursor));
+
+        /*
+         * We enter a new window. Announce the XdndEnter event to the new
          * window. The first three mime types are attached to the event (the
          * others could be requested by the XdndTypeList property from the
-         * window itself). */
-
+         * window itself).
+         */
         XClientMessageEvent m;
         RT_ZERO(m);
         m.type         = ClientMessage;
         m.display      = m_pDisplay;
-        m.window       = newWin;
+        m.window       = wndCursor;
         m.message_type = xAtom(XA_XdndEnter);
         m.format       = 32;
-        m.data.l[0]    = m_proxyWin;
+        m.data.l[0]    = m_wndProxy;
         m.data.l[1]    = RT_MAKE_U32_FROM_U8(m_formats.size() > 3 ? 1 : 0, 0, 0, RT_MIN(VBOX_XDND_VERSION, newVer));
         m.data.l[2]    = m_formats.value(0, None);
@@ -722,17 +747,19 @@
         m.data.l[4]    = m_formats.value(2, None);
 
-        xrc = XSendEvent(m_pDisplay, newWin, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
+        xrc = XSendEvent(m_pDisplay, wndCursor, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
         if (RT_UNLIKELY(xrc == 0))
-            DO(("DnD_MOVE: error sending xevent\n"));
+            LogFlowThisFunc(("Error sending XA_XdndEnter to new window=%#x\n", wndCursor));
     }
 
     if (newVer != -1)
     {
-        DO(("move=%#x pos=%ux%u ", newWin, u32xPos, u32yPos));
-
-        /* Send a XdndPosition event with the proposed action to the guest. */
-
-        Atom pa = toX11Action(action);
-        DO(("action='%s' ", xAtomToString(pa).c_str()));
+        LogFlowThisFunc(("Moving window=%#x, xPos=%RU32, yPos=%RU32\n",
+                         wndCursor, u32xPos, u32yPos));
+
+        /*
+         * Send a XdndPosition event with the proposed action to the guest.
+         */
+        Atom pa = toX11Action(uAction);
+        LogFlowThisFunc(("strAction='%s' ", xAtomToString(pa).c_str()));
 
         XClientMessageEvent m;
@@ -740,25 +767,27 @@
         m.type         = ClientMessage;
         m.display      = m_pDisplay;
-        m.window       = newWin;
+        m.window       = wndCursor;
         m.message_type = xAtom(XA_XdndPosition);
         m.format       = 32;
-        m.data.l[0]    = m_proxyWin;
+        m.data.l[0]    = m_wndProxy;
         m.data.l[2]    = RT_MAKE_U32(u32yPos, u32xPos);
         m.data.l[3]    = CurrentTime;
         m.data.l[4]    = pa;
 
-        xrc = XSendEvent(m_pDisplay, newWin, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
+        xrc = XSendEvent(m_pDisplay, wndCursor, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
         if (RT_UNLIKELY(xrc == 0))
-            DO(("DnD_MOVE: error sending xevent\n"));
-    }
-    if (newWin == None && newVer == -1)
+            LogFlowThisFunc(("Error sending XA_XdndPosition to window=%#x\n", wndCursor));
+    }
+
+    if (wndCursor == None && newVer == -1)
+    {
         /* No window to process, so send a ignore ack event to the host. */
-        rc = VbglR3DnDHGAcknowledgeOperation(DND_IGNORE_ACTION);
-
-    m_curWin = newWin;
+        rc = VbglR3DnDHGAcknowledgeOperation(m_uClientID, DND_IGNORE_ACTION);
+    }
+
+    m_wndCur = wndCursor;
     m_curVer = RT_MIN(VBOX_XDND_VERSION, newVer);
 
-    DO(("\n"));
-
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -774,36 +803,43 @@
     int rc = VINF_SUCCESS;
     if (   e.xclient.message_type == xAtom(XA_XdndStatus)
-        && m_curWin               == static_cast<Window>(e.xclient.data.l[0]))
+        && m_wndCur               == static_cast<Window>(e.xclient.data.l[0]))
     {
         /* The XdndStatus message tell us if the window will accept the DnD
          * event and with which action. We immediately send this info down to
          * the host as a response of a previous DnD message. */
-        DO(("DnD_STAT: win=%#x,accept=%RTbool,action='%s'\n",
-            e.xclient.data.l[0],
-            ASMBitTest(&e.xclient.data.l[1], 0),
-            xAtomToString(e.xclient.data.l[4]).c_str()));
+        LogFlowThisFunc(("XA_XdndStatus wnd=%#x, accept=%RTbool, action='%s'\n",
+                         e.xclient.data.l[0],
+                         ASMBitTest(&e.xclient.data.l[1], 0),
+                         xAtomToString(e.xclient.data.l[4]).c_str()));
+
         uint32_t uAction = DND_IGNORE_ACTION;
-        /* Todo: compare this with the allowed actions. */
+        /** @todo Compare this with the allowed actions. */
         if (ASMBitTest(&e.xclient.data.l[1], 0))
             uAction = toHGCMAction(static_cast<Atom>(e.xclient.data.l[4]));
-        rc = VbglR3DnDHGAcknowledgeOperation(uAction);
+
+        rc = VbglR3DnDHGAcknowledgeOperation(m_uClientID, uAction);
     }
     else if (e.xclient.message_type == xAtom(XA_XdndFinished))
     {
         /* This message is send on a un/successful DnD drop request. */
-        DO(("DnD_FINI: win=%#x,success=%RTbool,action='%s'\n",
+        LogFlowThisFunc(("XA_XdndFinished: wnd=%#x, success=%RTbool, action='%s'\n",
             e.xclient.data.l[0],
             ASMBitTest(&e.xclient.data.l[1], 0),
             xAtomToString(e.xclient.data.l[2]).c_str()));
+
         reset();
     }
     else
-        DO(("DnD_CLI: win=%#x,msg='%s'\n", e.xclient.data.l[0], xAtomToString(e.xclient.message_type).c_str()));
+        LogFlowThisFunc(("Unhandled: wnd=%#x, msg='%s'\n",
+                         e.xclient.data.l[0], xAtomToString(e.xclient.message_type).c_str()));
+
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
 
-int DragInstance::hgDrop()
-{
-    DO(("DnD_DROP: win=%#x\n", m_curWin));
+int DragInstance::hgDrop(void)
+{
+    LogFlowThisFunc(("wndCur=%#x, mMode=%RU32, mState=%RU32\n",
+                     m_wndCur, m_mode, m_state));
 
     if (   m_mode  != HG
@@ -818,19 +854,20 @@
     m.type         = ClientMessage;
     m.display      = m_pDisplay;
-    m.window       = m_curWin;
+    m.window       = m_wndCur;
     m.message_type = xAtom(XA_XdndDrop);
     m.format       = 32;
-    m.data.l[0]    = m_proxyWin;
+    m.data.l[0]    = m_wndProxy;
     m.data.l[2]    = CurrentTime;
 
-    int xrc = XSendEvent(m_pDisplay, m_curWin, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
+    int xrc = XSendEvent(m_pDisplay, m_wndCur, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
     if (RT_UNLIKELY(xrc == 0))
-        DO(("DnD_DROP: error sending xevent\n"));
-
-    m_curWin = None;
+        LogFlowThisFunc(("Error sending XA_XdndDrop to window=%#x\n", m_wndCur));
+
+    m_wndCur = None;
     m_curVer = -1;
 
     m_state = Dropped;
 
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -844,27 +881,31 @@
         return VERR_INVALID_STATE;
 
-    DO(("DnD_SELR: owner=%#x,requestor=%#x,sel_atom='%s',tar_atom='%s',prop_atom='%s',time=%u\n",
-        e.xselectionrequest.owner,
-        e.xselectionrequest.requestor,
-        xAtomToString(e.xselectionrequest.selection).c_str(),
-        xAtomToString(e.xselectionrequest.target).c_str(),
-        xAtomToString(e.xselectionrequest.property).c_str(),
-        e.xselectionrequest.time));
+    LogFlowThisFunc(("owner=%#x, requestor=%#x, sel_atom='%s', tar_atom='%s', prop_atom='%s', time=%u\n",
+                     e.xselectionrequest.owner,
+                     e.xselectionrequest.requestor,
+                     xAtomToString(e.xselectionrequest.selection).c_str(),
+                     xAtomToString(e.xselectionrequest.target).c_str(),
+                     xAtomToString(e.xselectionrequest.property).c_str(),
+                     e.xselectionrequest.time));
 
     int rc = VINF_SUCCESS;
 
-    /* A window is asking for some data. Normally here the data would be copied
+    /*
+     * A window is asking for some data. Normally here the data would be copied
      * into the selection buffer and send to the requestor. Obviously we can't
      * do that, cause we first need to ask the host for the data of the
      * requested mime type. This is done and later answered with the correct
-     * data (s. dataReceived). */
+     * data (s. dataReceived).
+     */
 
     /* Is the requestor asking for the possible mime types? */
     if(e.xselectionrequest.target == xAtom(XA_TARGETS))
     {
-        DO(("DnD_SELR: ask for target list\n"));
+        LogFlowThisFunc(("wnd=%#x asking for target list\n", e.xselectionrequest.requestor));
+
         /* If so, set the window property with the formats on the requestor
          * window. */
         setFormatsWindowProperty(e.xselectionrequest.requestor, e.xselectionrequest.property);
+
         XEvent s;
         RT_ZERO(s);
@@ -876,12 +917,15 @@
         s.xselection.target    = e.xselectionrequest.target;
         s.xselection.property  = e.xselectionrequest.property;
+
         int xrc = XSendEvent(e.xselection.display, e.xselectionrequest.requestor, False, 0, &s);
         if (RT_UNLIKELY(xrc == 0))
-            DO(("DnD_SELR: error sending xevent\n"));
+            LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", e.xselectionrequest.requestor));
     }
     /* Is the requestor asking for a specific mime type (we support)? */
     else if(m_formats.contains(e.xselectionrequest.target))
     {
-        DO(("DnD_SELR: ask for data (format='%s')\n", xAtomToString(e.xselectionrequest.target).c_str()));
+        LogFlowThisFunc(("wnd=%#x asking for data (format='%s')\n",
+                         e.xselectionrequest.requestor, xAtomToString(e.xselectionrequest.target).c_str()));
+
         /* If so, we need to inform the host about this request. Save the
          * selection request event for later use. */
@@ -889,5 +933,6 @@
             //        || m_curWin != e.xselectionrequest.requestor)
         {
-            DO(("DnD_SELR: refuse\n"));
+            LogFlowThisFunc(("Refusing ...\n"));
+
             XEvent s;
             RT_ZERO(s);
@@ -899,12 +944,15 @@
             s.xselection.target    = None;
             s.xselection.property  = e.xselectionrequest.property;
+
             int xrc = XSendEvent(e.xselection.display, e.xselectionrequest.requestor, False, 0, &s);
             if (RT_UNLIKELY(xrc == 0))
-                DO(("DnD_SELR: error sending xevent\n"));
+                LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", e.xselectionrequest.requestor));
         }
         else
         {
+            LogFlowThisFunc(("Copying data from host ...\n"));
+
             memcpy(&m_selEvent, &e, sizeof(XEvent));
-            rc = VbglR3DnDHGRequestData(xAtomToString(e.xselectionrequest.target).c_str());
+            rc = VbglR3DnDHGRequestData(m_uClientID, xAtomToString(e.xselectionrequest.target).c_str());
         }
     }
@@ -912,5 +960,6 @@
     else
     {
-        DO(("DnD_SELR: refuse\n"));
+        LogFlowThisFunc(("Refusing unknown command\n"));
+
         /* We don't understand this request message and therefore answer with an
          * refusal messages. */
@@ -926,7 +975,8 @@
         int xrc = XSendEvent(e.xselection.display, e.xselectionrequest.requestor, False, 0, &s);
         if (RT_UNLIKELY(xrc == 0))
-            DO(("DnD_SELR: error sending xevent\n"));
-    }
-
+            LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", e.xselectionrequest.requestor));
+    }
+
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -951,7 +1001,9 @@
     memcpy(pvNewData, pvData, cData);
 
-    /* The host send us the DnD data in the requested mime type. This allows us
+    /*
+     * The host send us the DnD data in the requested mime type. This allows us
      * to fill the XdndSelection property of the requestor window with the data
-     * and afterwards inform him about the new status. */
+     * and afterwards inform him about the new status.
+     */
     XEvent s;
     RT_ZERO(s);
@@ -965,11 +1017,11 @@
     s.xselection.property  = m_selEvent.xselectionrequest.property;
 
-    DO(("DnD_SEND: owner=%#x,requestor=%#x,sel_atom='%s',tar_atom='%s',prop_atom='%s',time=%u\n",
-        m_selEvent.xselectionrequest.owner,
-        s.xselection.requestor,
-        xAtomToString(s.xselection.selection).c_str(),
-        xAtomToString(s.xselection.target).c_str(),
-        xAtomToString(s.xselection.property).c_str(),
-        s.xselection.time));
+    LogFlowThisFunc(("owner=%#x,requestor=%#x,sel_atom='%s',tar_atom='%s',prop_atom='%s',time=%u\n",
+                     m_selEvent.xselectionrequest.owner,
+                     s.xselection.requestor,
+                     xAtomToString(s.xselection.selection).c_str(),
+                     xAtomToString(s.xselection.target).c_str(),
+                     xAtomToString(s.xselection.property).c_str(),
+                     s.xselection.time));
 
     /* Fill up the property with the data. */
@@ -978,5 +1030,5 @@
     int xrc = XSendEvent(s.xselection.display, s.xselection.requestor, True, 0, &s);
     if (RT_UNLIKELY(xrc == 0))
-        DO(("DnD_SEND: error sending xevent\n"));
+        LogFlowThisFunc(("Error sending SelectionNotify event to wnd=%#x\n", s.xselection.requestor));
 
     return VINF_SUCCESS;
@@ -989,12 +1041,13 @@
  */
 
-int DragInstance::ghIsDnDPending()
+int DragInstance::ghIsDnDPending(void)
 {
     int rc = VINF_SUCCESS;
-    Window w = XGetSelectionOwner(m_pDisplay, xAtom(XA_XdndSelection));
-    DO(("Checking pending %X %X\n", w, m_proxyWin));
+    Window wndOwner = XGetSelectionOwner(m_pDisplay, xAtom(XA_XdndSelection));
+    LogFlowThisFunc(("Checking pending wndOwner=%#x wndProxy=%#x\n", wndOwner, m_wndProxy));
+
     /* Is there someone own the Xdnd selection which aren't we. */
-    if (   w
-        && w != m_proxyWin)
+    if (   wndOwner
+        && wndOwner != m_wndProxy)
     {
         /* Map the window on the current cursor position, which should provoke
@@ -1007,5 +1060,5 @@
             int xrc = Success;
             XClientMessageEvent *clme = reinterpret_cast<XClientMessageEvent*>(&e);
-            DO(("next X event %s\n", gX11->xAtomToString(clme->message_type).c_str()));
+            LogFlowThisFunc(("Next X event %s\n", gX11->xAtomToString(clme->message_type).c_str()));
             if (clme->message_type == xAtom(XA_XdndEnter))
             {
@@ -1018,6 +1071,6 @@
                 m_formats.clear();
                 m_actions.clear();
-                m_curWin = w;
-                DO(("XA_XdndEnter\n"));
+                m_wndCur = wndOwner;
+                LogFlowThisFunc(("XA_XdndEnter\n"));
                 /* Check if the mime types are in the msg itself or if we need
                  * to fetch the XdndTypeList property from the window. */
@@ -1026,5 +1079,5 @@
                     for (int i = 2; i < 5; ++i)
                     {
-                        DO(("receive list msg: %s\n", gX11->xAtomToString(clme->data.l[i]).c_str()));
+                        LogFlowThisFunc(("Receive list msg: %s\n", gX11->xAtomToString(clme->data.l[i]).c_str()));
                         m_formats.append(clme->data.l[i]);
                     }
@@ -1032,5 +1085,5 @@
                 else
                 {
-                    xrc = XGetWindowProperty(m_pDisplay, w, xAtom(XA_XdndTypeList), 0, VBOX_MAX_XPROPERTIES, False, XA_ATOM, &type, &f, &n, &a, &ret);
+                    xrc = XGetWindowProperty(m_pDisplay, wndOwner, xAtom(XA_XdndTypeList), 0, VBOX_MAX_XPROPERTIES, False, XA_ATOM, &type, &f, &n, &a, &ret);
                     if (   xrc == Success
                         && n > 0
@@ -1040,5 +1093,5 @@
                         for (int i = 0; i < RT_MIN(VBOX_MAX_XPROPERTIES, n); ++i)
                         {
-                            DO(("receive list: %s\n", gX11->xAtomToString(data[i]).c_str()));
+                            LogFlowThisFunc(("Receive list: %s\n", gX11->xAtomToString(data[i]).c_str()));
                             m_formats.append(data[i]);
                         }
@@ -1047,5 +1100,5 @@
                 }
                 /* Fetch the possible list of actions, if this property is set. */
-                xrc = XGetWindowProperty(m_pDisplay, w, xAtom(XA_XdndActionList), 0, VBOX_MAX_XPROPERTIES, False, XA_ATOM, &type, &f, &n, &a, &ret);
+                xrc = XGetWindowProperty(m_pDisplay, wndOwner, xAtom(XA_XdndActionList), 0, VBOX_MAX_XPROPERTIES, False, XA_ATOM, &type, &f, &n, &a, &ret);
                 if (   xrc == Success
                     && n > 0
@@ -1055,5 +1108,5 @@
                     for (int i = 0; i < RT_MIN(VBOX_MAX_XPROPERTIES, n); ++i)
                     {
-                        DO(("receive actions: %s\n", gX11->xAtomToString(data[i]).c_str()));
+                        LogFlowThisFunc(("Receive actions: %s\n", gX11->xAtomToString(data[i]).c_str()));
                         m_actions.append(data[i]);
                     }
@@ -1072,14 +1125,14 @@
                 m.message_type = xAtom(XA_XdndStatus);
                 m.format       = 32;
-                m.data.l[0]    = m_proxyWin;
+                m.data.l[0]    = m_wndProxy;
                 m.data.l[1]    = 1;
                 m.data.l[4]    = xAtom(XA_XdndActionCopy);
                 xrc = XSendEvent(m_pDisplay, clme->data.l[0], False, 0, reinterpret_cast<XEvent*>(&m));
                 if (RT_UNLIKELY(xrc == 0))
-                    DO(("DnD_PNDG: error sending xevent\n"));
+                    LogFlowThisFunc(("Error sending xevent\n"));
             }
             else if (clme->message_type == xAtom(XA_XdndPosition))
             {
-                DO(("XA_XdndPosition\n"));
+                LogFlowThisFunc(("XA_XdndPosition\n"));
                 XClientMessageEvent m;
                 RT_ZERO(m);
@@ -1089,10 +1142,10 @@
                 m.message_type = xAtom(XA_XdndStatus);
                 m.format       = 32;
-                m.data.l[0]    = m_proxyWin;
+                m.data.l[0]    = m_wndProxy;
                 m.data.l[1]    = 1;
                 m.data.l[4]    = clme->data.l[4];
                 xrc = XSendEvent(m_pDisplay, clme->data.l[0], False, 0, reinterpret_cast<XEvent*>(&m));
                 if (RT_UNLIKELY(xrc == 0))
-                    DO(("DnD_PNDG: error sending xevent\n"));
+                    LogFlowThisFunc(("Error sending xevent\n"));
             }
             else if (clme->message_type == xAtom(XA_XdndLeave))
@@ -1102,6 +1155,9 @@
         hideProxyWin();
 
-        rc = VbglR3DnDGHAcknowledgePending(DND_COPY_ACTION, toHGCMActions(m_actions), gX11->xAtomListToString(m_formats).c_str());
-    }
+        rc = VbglR3DnDGHAcknowledgePending(DND_COPY_ACTION, toHGCMActions(m_actions),
+                                           gX11->xAtomListToString(m_formats).c_str());
+    }
+
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -1109,5 +1165,5 @@
 int DragInstance::ghDropped(const RTCString &strFormat, uint32_t action)
 {
-    DO(("DND_DRO: format='%s' action=%d\n", strFormat.c_str(), action));
+    LogFlowThisFunc(("format='%s' action=%d\n", strFormat.c_str(), action));
     int rc = VINF_SUCCESS;
 
@@ -1118,5 +1174,5 @@
     /* We send a fake release event to the current window, cause
      * this should have the grab. */
-    sendButtonEvent(m_curWin, rx, ry, 1, false);
+    sendButtonEvent(m_wndCur, rx, ry, 1, false);
     /* The fake button release event, should lead to an XdndDrop event from the
      * source. Because of the showing of the proxy window, sometimes other Xdnd
@@ -1145,7 +1201,7 @@
             /* Request to convert the selection in the specific format and
              * place it to our proxy window as property. */
-            Window srcWin = m_curWin;//clme->data.l[0];
+            Window srcWin = m_wndCur;//clme->data.l[0];
             Atom aFormat  = gX11->stringToxAtom(strFormat.c_str());
-            XConvertSelection(m_pDisplay, xAtom(XA_XdndSelection), aFormat, xAtom(XA_XdndSelection), m_proxyWin, clme->data.l[2]);
+            XConvertSelection(m_pDisplay, xAtom(XA_XdndSelection), aFormat, xAtom(XA_XdndSelection), m_wndProxy, clme->data.l[2]);
             /* Wait for the selection notify event. */
             RT_ZERO(e);
@@ -1156,16 +1212,16 @@
                     && e.xselection.display   == m_pDisplay
                     && e.xselection.selection == xAtom(XA_XdndSelection)
-                    && e.xselection.requestor == m_proxyWin
+                    && e.xselection.requestor == m_wndProxy
                     && e.xselection.target    == aFormat)
                 {
-                    DO(("DND_DRO: selection notfiy (from: %x)\n", m_curWin));
+                    LogFlowThisFunc(("Selection notfiy (from: %x)\n", m_wndCur));
                     Atom type;
                     int format;
                     unsigned long cItems, cbRemaining;
                     unsigned char *ucData = 0;
-                    XGetWindowProperty(m_pDisplay, m_proxyWin, xAtom(XA_XdndSelection),
+                    XGetWindowProperty(m_pDisplay, m_wndProxy, xAtom(XA_XdndSelection),
                                        0, VBOX_MAX_XPROPERTIES, True, AnyPropertyType,
                                        &type, &format, &cItems, &cbRemaining, &ucData);
-                    DO(("DND_DRO: %s %d %d %s\n", gX11->xAtomToString(type).c_str(), cItems, format, ucData));
+                    LogFlowThisFunc(("%s %d %d %s\n", gX11->xAtomToString(type).c_str(), cItems, format, ucData));
                     if (   type        != None
                         && ucData      != NULL
@@ -1181,5 +1237,5 @@
                             && ucData[cbData - 1] != '\0')
                         {
-                            DO(("rebuild %u\n", cbData));
+                            LogFlowThisFunc(("Rebuild %u\n", cbData));
                             unsigned char *ucData1 = static_cast<unsigned char*>(RTMemAlloc(cbData + 1));
                             if (ucData1)
@@ -1198,5 +1254,5 @@
                             rc = VbglR3DnDGHSendData(ucData, cbData);
 
-                        DO(("send responce\n"));
+                        LogFlowThisFunc(("send responce\n"));
                         /* Confirm the result of the transfer to the source window. */
                         XClientMessageEvent m;
@@ -1207,5 +1263,5 @@
                         m.message_type = xAtom(XA_XdndFinished);
                         m.format       = 32;
-                        m.data.l[0]    = m_proxyWin;
+                        m.data.l[0]    = m_wndProxy;
                         m.data.l[1]    = RT_SUCCESS(rc) ?                   1 : 0;    /* Confirm or deny success */
                         m.data.l[2]    = RT_SUCCESS(rc) ? toX11Action(action) : None; /* Action used on success */
@@ -1213,5 +1269,5 @@
                         int xrc = XSendEvent(m_pDisplay, srcWin, True, NoEventMask, reinterpret_cast<XEvent*>(&m));
                         if (RT_UNLIKELY(xrc == 0))
-                            DO(("DnD_DRO: error sending xevent\n"));
+                            LogFlowThisFunc(("Error sending xevent\n"));
                     }
                     else
@@ -1236,11 +1292,11 @@
                         m.message_type = xAtom(XA_XdndFinished);
                         m.format       = 32;
-                        m.data.l[0]    = m_proxyWin;
+                        m.data.l[0]    = m_wndProxy;
                         m.data.l[1]    = 0;
                         m.data.l[2]    = None;
                         int xrc = XSendEvent(m_pDisplay, srcWin, False, NoEventMask, reinterpret_cast<XEvent*>(&m));
                         if (RT_UNLIKELY(xrc == 0))
-                            DO(("DnD_DRO: error sending xevent\n"));
-                        m_curWin = 0;
+                            LogFlowThisFunc(("Error sending xevent\n"));
+                        m_wndCur = 0;
                     }
                     /* Cleanup */
@@ -1268,4 +1324,5 @@
     reset();
 
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -1281,5 +1338,5 @@
     /* Move the guest pointer to the DnD position, so we can find the window
      * below that position. */
-    XWarpPointer(m_pDisplay, None, m_rootWin, 0, 0, 0, 0, u32xPos, u32yPos);
+    XWarpPointer(m_pDisplay, None, m_wndRoot, 0, 0, 0, 0, u32xPos, u32yPos);
     return VINF_SUCCESS;
 }
@@ -1295,5 +1352,5 @@
         RT_ZERO(be);
         be.display      = m_pDisplay;
-        be.root         = m_rootWin;
+        be.root         = m_wndRoot;
         be.window       = w;
         be.subwindow    = None;
@@ -1312,7 +1369,6 @@
         int xrc = XSendEvent(m_pDisplay, be.window, True, ButtonPressMask, reinterpret_cast<XEvent*>(&be));
         if (RT_UNLIKELY(xrc == 0))
-            DO(("DnD_BTN: error sending xevent\n"));
-    }
-
+            LogFlowThisFunc(("Error sending xevent\n"));
+    }
 }
 
@@ -1323,33 +1379,33 @@
     Window r, c;
 //    XTestGrabControl(m_pDisplay, False);
-    XQueryPointer(m_pDisplay, m_rootWin, &r, &c, &rx, &ry, &cx, &cy, &m);
+    XQueryPointer(m_pDisplay, m_wndRoot, &r, &c, &rx, &ry, &cx, &cy, &m);
     XSynchronize(m_pDisplay, True);
-    XMapWindow(m_pDisplay, m_proxyWin);
-    XRaiseWindow(m_pDisplay, m_proxyWin);
-    XMoveResizeWindow(m_pDisplay, m_proxyWin, rx, ry, 1, 1);
-    XWarpPointer(m_pDisplay, None, m_rootWin, 0, 0, 0, 0, rx , ry);
+    XMapWindow(m_pDisplay, m_wndProxy);
+    XRaiseWindow(m_pDisplay, m_wndProxy);
+    XMoveResizeWindow(m_pDisplay, m_wndProxy, rx, ry, 1, 1);
+    XWarpPointer(m_pDisplay, None, m_wndRoot, 0, 0, 0, 0, rx , ry);
     XSynchronize(m_pDisplay, False);
 //    XTestGrabControl(m_pDisplay, True);
 }
 
-void DragInstance::hideProxyWin() const
-{
-    XUnmapWindow(m_pDisplay, m_proxyWin);
+void DragInstance::hideProxyWin(void) const
+{
+    XUnmapWindow(m_pDisplay, m_wndProxy);
 }
 
 /* Currently, not used */
-void DragInstance::registerForEvents(Window w) const
+void DragInstance::registerForEvents(Window wndThis) const
 {
 //    if (w == m_proxyWin)
 //        return;
 
-    DO(("%x\n", w));
+    LogFlowThisFunc(("%x\n", wndThis));
 //    XSelectInput(m_pDisplay, w, Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask);//| SubstructureNotifyMask);
 //    XSelectInput(m_pDisplay, w, ButtonMotionMask); //PointerMotionMask);
-    XSelectInput(m_pDisplay, w, PointerMotionMask); //PointerMotionMask);
+    XSelectInput(m_pDisplay, wndThis, PointerMotionMask); //PointerMotionMask);
     Window hRealRoot, hParent;
     Window *phChildrenRaw = NULL;
     unsigned cChildren;
-    if (XQueryTree(m_pDisplay, w, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))
+    if (XQueryTree(m_pDisplay, wndThis, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))
     {
         for (unsigned i = 0; i < cChildren; ++i)
@@ -1359,19 +1415,19 @@
 }
 
-void DragInstance::setActionsWindowProperty(Window win, const RTCList<Atom> &actionList) const
+void DragInstance::setActionsWindowProperty(Window wndThis, const RTCList<Atom> &actionList) const
 {
     if (actionList.isEmpty())
         return;
 
-    XChangeProperty(m_pDisplay, win, xAtom(XA_XdndActionList), XA_ATOM, 32, PropModeReplace,
+    XChangeProperty(m_pDisplay, wndThis, xAtom(XA_XdndActionList), XA_ATOM, 32, PropModeReplace,
                     reinterpret_cast<const unsigned char*>(actionList.raw()), actionList.size());
 }
 
-void DragInstance::clearActionsWindowProperty(Window win) const
-{
-    XDeleteProperty(m_pDisplay, win, xAtom(XA_XdndActionList));
-}
-
-void DragInstance::setFormatsWindowProperty(Window win, Atom property) const
+void DragInstance::clearActionsWindowProperty(Window wndThis) const
+{
+    XDeleteProperty(m_pDisplay, wndThis, xAtom(XA_XdndActionList));
+}
+
+void DragInstance::setFormatsWindowProperty(Window wndThis, Atom property) const
 {
     if (m_formats.isEmpty())
@@ -1384,11 +1440,11 @@
 
     /* Add the property with the property data to the window. */
-    XChangeProperty(m_pDisplay, win, property, XA_ATOM, 32, PropModeReplace,
+    XChangeProperty(m_pDisplay, wndThis, property, XA_ATOM, 32, PropModeReplace,
                     reinterpret_cast<const unsigned char*>(targets.raw()), targets.size());
 }
 
-void DragInstance::clearFormatsWindowProperty(Window win) const
-{
-    XDeleteProperty(m_pDisplay, win, xAtom(XA_XdndTypeList));
+void DragInstance::clearFormatsWindowProperty(Window wndThis) const
+{
+    XDeleteProperty(m_pDisplay, wndThis, xAtom(XA_XdndTypeList));
 }
 
@@ -1417,5 +1473,5 @@
          * even if the data isn't zero terminated. */
         char *pszTmp = RTStrDupN(pszStr, cSize);
-        DO(("f: %s\n", pszTmp));
+        LogFlowThisFunc(("f: %s\n", pszTmp));
         atomList.append(XInternAtom(m_pDisplay, pszTmp, False));
         RTStrFree(pszTmp);
@@ -1512,5 +1568,5 @@
         if (!m_eventQueue.isEmpty())
         {
-            DO(("new msg size %d\n", m_eventQueue.size()));
+            LogFlowThisFunc(("new msg size %d\n", m_eventQueue.size()));
             /* Check if there is a client message in the queue. */
             for (size_t i = 0; i < m_eventQueue.size(); ++i)
@@ -1518,5 +1574,5 @@
                 DnDEvent e = m_eventQueue.at(i);
                 if(   e.type     == DnDEvent::X11_Type)
-                    DO(("new msg\n"));
+                    LogFlowThisFunc(("new msg\n"));
                 if(   e.type     == DnDEvent::X11_Type
                    && e.x11.type == type)
@@ -1551,9 +1607,4 @@
     do
     {
-        /* Initialize our service */
-        rc = VbglR3DnDInit();
-        if (RT_FAILURE(rc))
-            break;
-
         /* Initialize X11 DND */
         rc = x11DragAndDropInit();
@@ -1562,8 +1613,16 @@
 
         m_pCurDnD = new DragInstance(m_pDisplay, this);
+        if (!m_pCurDnD) 
+        {
+            rc = VERR_NO_MEMORY;
+            break;
+        }
         /* Note: For multiple screen support in VBox it is not necessary to use
          * another screen number than zero. Maybe in the future it will become
          * necessary if VBox supports multiple X11 screens. */
-        m_pCurDnD->init(0);
+        rc = m_pCurDnD->init(0);
+        if (RT_FAILURE(rc))
+            break;
+
         /* Loop over new events */
         do
@@ -1577,5 +1636,5 @@
                 e = m_eventQueue.first();
                 m_eventQueue.removeFirst();
-                DO(("new msg %d\n", e.type));
+                LogFlowThisFunc(("new msg %d\n", e.type));
                 if (e.type == DnDEvent::HGCM_Type)
                 {
@@ -1624,5 +1683,9 @@
                         }
 #endif
+                        default:
+                            LogFlowThisFunc(("Unknown message: %RU32\n", e.hgcm.uType));
+                            break;
                     }
+
                     /* Some messages require cleanup. */
                     switch (e.hgcm.uType)
@@ -1647,10 +1710,11 @@
                             break;
                         }
+                        default:
+                            break;
                     }
-
                 }
                 else if(e.type == DnDEvent::X11_Type)
                 {
-                    DO(("X11 type: %u\n", e.x11.type));
+                    LogFlowThisFunc(("X11 type: %u\n", e.x11.type));
                     /* Now the X11 event stuff */
                     switch (e.x11.type)
@@ -1658,5 +1722,5 @@
                         case SelectionRequest: m_pCurDnD->hgX11SelectionRequest(e.x11); break;
                         case ClientMessage:    m_pCurDnD->hgX11ClientMessage(e.x11); break;
-                        case SelectionClear:   DO(("DnD_CLER\n")); break;
+                        case SelectionClear:   LogFlowThisFunc(("DnD_CLER\n")); break;
 //                      case MotionNotify: m_pCurDnD->hide(); break;
                     }
@@ -1666,9 +1730,9 @@
     } while (0);
 
-    LogRelFlowFunc(("returning %Rrc\n", rc));
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
 
-int DragAndDropService::x11DragAndDropInit()
+int DragAndDropService::x11DragAndDropInit(void)
 {
     /* Connect to the x11 server. */
@@ -1678,5 +1742,7 @@
         return VERR_NOT_FOUND;
 
-    xHelpers::instance(m_pDisplay);
+    xHelpers *pHelpers = xHelpers::getInstance(m_pDisplay);
+    if (!pHelpers)
+        return VERR_NO_MEMORY;
 
     int rc = VINF_SUCCESS;
@@ -1706,5 +1772,5 @@
 }
 
-int DragAndDropService::x11DragAndDropTerm()
+int DragAndDropService::x11DragAndDropTerm(void)
 {
     /* Mark that we are stopping. */
@@ -1724,5 +1790,5 @@
         int xrc = XSendEvent(m_pDisplay, None, True, NoEventMask, reinterpret_cast<XEvent*>(&m));
         if (RT_UNLIKELY(xrc == 0))
-                DO(("DnD_TERM: error sending xevent\n"));
+            LogFlowThisFunc(("Error sending xevent\n"));
     }
 
@@ -1755,4 +1821,12 @@
     DragAndDropService *pThis = static_cast<DragAndDropService*>(pvUser);
     DnDEvent e;
+
+    uint32_t uClientID;
+    int rc = VbglR3DnDConnect(&uClientID);
+    if (RT_FAILURE(rc)) {
+        LogFlowFunc(("Unable to connect to HGCM service, rc=%Rrc\n", rc));
+        return rc;
+    }
+
     do
     {
@@ -1760,5 +1834,5 @@
         e.type = DnDEvent::HGCM_Type;
         /* Wait for new events */
-        int rc = VbglR3DnDProcessNextMessage(&e.hgcm);
+        rc = VbglR3DnDProcessNextMessage(uClientID, &e.hgcm);
         if (RT_SUCCESS(rc))
         {
@@ -1769,4 +1843,6 @@
         }
     } while (!ASMAtomicReadBool(&pThis->m_fSrvStopping));
+
+    VbglR3DnDDisconnect(uClientID);
 
     return VINF_SUCCESS;
@@ -1815,6 +1891,8 @@
 
 /* Static factory */
-VBoxClient::Service *VBoxClient::GetDragAndDropService()
-{
-    return new(DragAndDropService);
-}
+VBoxClient::Service *VBoxClient::GetDragAndDropService(void)
+{
+    DragAndDropService *pService = new DragAndDropService();
+    return pService;
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDHandler.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDHandler.cpp	(revision 49890)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDHandler.cpp	(revision 49891)
@@ -7,5 +7,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -25,4 +25,10 @@
 #include <QTimer>
 
+#ifdef LOG_GROUP
+# undef LOG_GROUP
+#endif
+#define LOG_GROUP LOG_GROUP_GUEST_DND
+#include <VBox/log.h>
+
 /* GUI includes: */
 #include "UIDnDHandler.h"
@@ -46,4 +52,7 @@
 Qt::DropAction UIDnDHandler::dragHGEnter(CGuest &guest, ulong screenId, int x, int y, Qt::DropAction proposedAction, Qt::DropActions possibleActions, const QMimeData *pMimeData, QWidget * /* pParent = 0 */)
 {
+    LogFlowFunc(("screenId=%RU32, x=%d, y=%d, action=%ld\n",
+                 screenId, x, y, toVBoxDnDAction(proposedAction)));
+
     /* Ask the guest for starting a DnD event. */
     KDragAndDropAction result = guest.DragHGEnter(screenId,
@@ -59,5 +68,11 @@
 Qt::DropAction UIDnDHandler::dragHGMove(CGuest &guest, ulong screenId, int x, int y, Qt::DropAction proposedAction, Qt::DropActions possibleActions, const QMimeData *pMimeData, QWidget * /* pParent = 0 */)
 {
-    /* Ask the guest for starting a DnD event. */
+#ifdef DEBUG_andy
+    LogFlowFunc(("screenId=%RU32, x=%d, y=%d, action=%ld\n",
+                 screenId, x, y, toVBoxDnDAction(proposedAction)));
+#endif
+
+    /* Notify the guest that the mouse has been moved while doing
+     * a drag'n drop operation. */
     KDragAndDropAction result = guest.DragHGMove(screenId,
                                                  x,
@@ -72,4 +87,7 @@
 Qt::DropAction UIDnDHandler::dragHGDrop(CGuest &guest, ulong screenId, int x, int y, Qt::DropAction proposedAction, Qt::DropActions possibleActions, const QMimeData *pMimeData, QWidget *pParent /* = 0 */)
 {
+    LogFlowFunc(("screenId=%RU32, x=%d, y=%d, action=%ld\n",
+                 screenId, x, y, toVBoxDnDAction(proposedAction)));
+
     /* The format the guest requests. */
     QString format;
@@ -116,4 +134,5 @@
 void UIDnDHandler::dragHGLeave(CGuest &guest, ulong screenId, QWidget * /* pParent = 0 */)
 {
+    LogFlowFunc(("screenId=%RU32\n", screenId));
     guest.DragHGLeave(screenId);
 }
@@ -144,5 +163,6 @@
       , m_fState(Dragging)
     {
-        /* This is unbelievable hacky, but I didn't found another way. Stupid
+        /*
+         * This is unbelievable hacky, but I didn't find another way. Stupid
          * Qt QDrag interface is so less verbose, that we in principle know
          * nothing about what happens when the user drag something around. It
@@ -158,5 +178,6 @@
          * one installed by the QDrag object.
          *
-         * Todo: test this on all supported platforms (X11 works) */
+         ** @todo: Test this on all supported platforms (X11 works).
+         */
         QTimer::singleShot(0, this, SLOT(sltInstallEventFilter()));
     }
@@ -258,5 +279,6 @@
 void UIDnDHandler::dragGHPending(CSession &session, ulong screenId, QWidget *pParent /* = 0 */)
 {
-    /* How does this work: Host is asking the guest if there is any DnD
+    /*
+     * How this works: Host is asking the guest if there is any DnD
      * operation pending, when the mouse leaves the guest window
      * (DragGHPending). On return there is some info about a running DnD
@@ -264,5 +286,6 @@
      * this information we create a Qt QDrag object with our own QMimeType
      * implementation and call exec. Please note, this *blocks* until the DnD
-     * operation has finished. */
+     * operation has finished.
+     */
     CGuest guest = session.GetConsole().GetGuest();
     QVector<QString> formats;
Index: /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp
===================================================================
--- /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp	(revision 49890)
+++ /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.cpp	(revision 49891)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,5 +20,8 @@
  ******************************************************************************/
 
-#define LOG_GROUP LOG_GROUP_HGCM
+#ifdef LOG_GROUP
+ #undef LOG_GROUP
+#endif
+#define LOG_GROUP LOG_GROUP_GUEST_DND
 
 #include "dndmanager.h"
@@ -29,14 +32,4 @@
 #include <iprt/path.h>
 #include <iprt/uri.h>
-
-#define VERBOSE 1
-
-#if defined(VERBOSE) && defined(DEBUG_poetzsch)
-# include <iprt/stream.h>
-# define DO(s) RTPrintf s
-#else
-# define DO(s) do {} while(0)
-//# define DO(s) Log s
-#endif
 
 /******************************************************************************
@@ -65,4 +58,5 @@
         paTmpParms[1].setUInt32(m_strPath.length() + 1);
         paTmpParms[2].setUInt32(fMode);
+
         m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_SND_DIR, 3, paTmpParms);
     }
@@ -97,5 +91,5 @@
 public:
     DnDHGSendFilePrivate(const RTCString &strHostPath, const RTCString &strGuestPath, uint32_t fMode, uint64_t cbSize, PFNDNDPRIVATEPROGRESS pfnProgressCallback, void *pvProgressUser);
-    ~DnDHGSendFilePrivate();
+    virtual ~DnDHGSendFilePrivate();
 
     int currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
@@ -104,6 +98,6 @@
     RTCString              m_strHostPath;
     RTCString              m_strGuestPath;
-    uint64_t               m_cbSize;
-    uint64_t               m_cbDone;
+    uint64_t               m_cbFileSize;
+    uint64_t               m_cbFileProcessed;
     RTFILE                 m_hCurFile;
     VBOXHGCMSVCPARM        m_paSkelParms[5];
@@ -146,6 +140,6 @@
   : m_strHostPath(strHostPath)
   , m_strGuestPath(strGuestPath)
-  , m_cbSize(cbSize)
-  , m_cbDone(0)
+  , m_cbFileSize(cbSize)
+  , m_cbFileProcessed(0)
   , m_hCurFile(0)
   , m_pfnProgressCallback(pfnProgressCallback)
@@ -157,4 +151,5 @@
     m_paSkelParms[3].setUInt32(0);
     m_paSkelParms[4].setUInt32(fMode);
+
     m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_SND_FILE, 5, m_paSkelParms);
 }
@@ -178,39 +173,60 @@
     if (!m_hCurFile)
     {
-        rc = RTFileOpen(&m_hCurFile, m_strHostPath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_ALL);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-
-    /* How big is the pointer provided by the guest? */
-    uint32_t cbToRead = paParms[2].u.pointer.size;
+        /* Open files on the host with RTFILE_O_DENY_WRITE to prevent races where the host
+         * writes to the file while the guest transfers it over. */
+        rc = RTFileOpen(&m_hCurFile, m_strHostPath.c_str(),
+                        RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
+    }
+
     size_t cbRead;
-    rc = RTFileRead(m_hCurFile, paParms[2].u.pointer.addr, cbToRead, &cbRead);
-    if (RT_FAILURE(rc))
-    {
-        /* On error, immediately close the file. */
-        RTFileClose(m_hCurFile);
-        m_hCurFile = 0;
-        return rc;
-    }
-    m_cbDone += cbRead;
-    /* Tell the guest the actual size. */
-    paParms[3].setUInt32(cbRead);
-    /* Check if we are done. */
-    if (m_cbSize == m_cbDone)
-    {
-        RTFileClose(m_hCurFile);
-        m_hCurFile = 0;
-    }
-    else
-    {
-        /* More data! Prepare the next message. */
-        m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_SND_FILE, 5, m_paSkelParms);
-    }
-
-    /* Advance progress info */
-    if (   RT_SUCCESS(rc)
-        && m_pfnProgressCallback)
-        rc = m_pfnProgressCallback(cbRead, m_pvProgressUser);
+    if (RT_SUCCESS(rc))
+    {
+        /* Get buffer size + pointer to buffer from guest side. */
+        uint32_t cbToRead = paParms[2].u.pointer.size;
+        Assert(cbToRead);
+        void *pvBuf = paParms[2].u.pointer.addr;
+        AssertPtr(pvBuf);
+        rc = RTFileRead(m_hCurFile, pvBuf, cbToRead, &cbRead);
+        if (RT_LIKELY(RT_SUCCESS(rc)))
+        {
+            /* Advance. */
+            m_cbFileProcessed += cbRead;
+            Assert(m_cbFileProcessed <= m_cbFileSize);
+
+            /* Tell the guest the actual size. */
+            paParms[3].setUInt32(cbRead);
+        }
+    }
+
+    if (RT_SUCCESS(rc))
+    {
+        /* Check if we are done. */
+        bool fDone = m_cbFileSize == m_cbFileProcessed;
+        if (!fDone)
+        {
+            try
+            {
+                /* More data! Prepare the next message. */
+                m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_SND_FILE, 5 /* cParms */,
+                                               m_paSkelParms);
+            }
+            catch(std::bad_alloc &)
+            {
+                rc = VERR_NO_MEMORY;
+            }
+        }
+
+        /* Advance progress info. */
+        if (   RT_SUCCESS(rc)
+            && m_pfnProgressCallback)
+            rc = m_pfnProgressCallback(cbRead, m_pvProgressUser);
+
+        if (   fDone
+            || RT_FAILURE(rc))
+        {
+            RTFileClose(m_hCurFile);
+            m_hCurFile = 0;
+        }
+    }
 
     return rc;
@@ -241,4 +257,6 @@
 
     HGCM::Message *pCurMsg = m_pNextMsg;
+    AssertPtr(pCurMsg);
+
     m_pNextMsg = 0;
     rc = pCurMsg->getData(uMsg, cParms, paParms);
@@ -258,6 +276,15 @@
         paTmpParms[0].setPointer(static_cast<uint8_t*>(pvOldData) + paParms[iPos].u.pointer.size, cOldData - paParms[iPos].u.pointer.size);
         paTmpParms[1].setUInt32(cOldData - paParms[iPos].u.pointer.size);
-        m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_SND_MORE_DATA, 2, paTmpParms);
-    }
+
+        try
+        {
+            m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_SND_MORE_DATA, 2, paTmpParms);
+        }
+        catch(std::bad_alloc &)
+        {
+            rc = VERR_NO_MEMORY;
+        }
+    }
+
     delete pCurMsg;
 
@@ -280,8 +307,8 @@
  */
 DnDHGSendDataMessage::DnDHGSendDataMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser)
-  : m_cbAll(0)
-  , m_cbTransfered(0)
-  , m_pfnProgressCallback(pfnProgressCallback)
-  , m_pvProgressUser(pvProgressUser)
+    : m_cbAll(0)
+    , m_cbTransfered(0)
+    , m_pfnProgressCallback(pfnProgressCallback)
+    , m_pvProgressUser(pvProgressUser)
 {
     RTCString strNewUris;
@@ -289,8 +316,9 @@
     if (hasFileUrls(static_cast<const char*>(paParms[1].u.pointer.addr), paParms[1].u.pointer.size))
     {
-        DO(("old data '%s'\n", (char*)paParms[3].u.pointer.addr));
+        LogFlowFunc(("Old data: '%s'\n", (char*)paParms[3].u.pointer.addr));
         /* The list is separated by newline (Even if only one file is
          * listed). */
-        RTCList<RTCString> oldUriList = RTCString(static_cast<const char*>(paParms[3].u.pointer.addr), paParms[3].u.pointer.size).split("\r\n");
+        RTCList<RTCString> oldUriList = RTCString(static_cast<const char*>(paParms[3].u.pointer.addr),
+                                                  paParms[3].u.pointer.size).split("\r\n");
         if (!oldUriList.isEmpty())
         {
@@ -337,12 +365,15 @@
     m_cbAll += paParms[4].u.uint32;
     /* The first message is the meta info for the data and the data itself. */
-    m_pNextPathMsg = new DnDHGSendDataMessagePrivate(uMsg, cParms, paParms, &DnDHGSendDataMessage::progressCallback, this);
-
-    DO(("new data '%s'\n", (char*)paParms[3].u.pointer.addr));
-    DO(("cbAll: %u\n", m_cbAll));
-    DO(("cbData: %u\n", paParms[4].u.uint32));
+    m_pNextPathMsg = new DnDHGSendDataMessagePrivate(uMsg, cParms, paParms,
+                                                     &DnDHGSendDataMessage::progressCallback, this);
+
+    LogFlowFunc(("new data '%s'\n", (char*)paParms[3].u.pointer.addr));
+    LogFlowFunc(("cbAll: %zu\n", m_cbAll));
+    LogFlowFunc(("cbData: %RU32\n", paParms[4].u.uint32));
 
     for (size_t i = 0; i < m_uriList.size(); ++i)
-        DO(("file: %s : %s - %o - %ld\n", m_uriList.at(i).m_strHostPath.c_str(), m_uriList.at(i).m_strGuestPath.c_str(), m_uriList.at(i).m_fMode, m_uriList.at(i).m_cbSize));
+        LogFlowFunc(("file: %s : %s - %o - %ld\n",
+                     m_uriList.at(i).m_strHostPath.c_str(), m_uriList.at(i).m_strGuestPath.c_str(),
+                     m_uriList.at(i).m_fMode, m_uriList.at(i).m_cbSize));
 }
 
@@ -391,12 +422,26 @@
          * this could be directories or regular files. */
         PathEntry nextPath = m_uriList.first();
-        if (RTFS_IS_DIRECTORY(nextPath.m_fMode))
-            m_pNextPathMsg = new DnDHGSendDirPrivate(nextPath.m_strGuestPath, nextPath.m_fMode, nextPath.m_cbSize, &DnDHGSendDataMessage::progressCallback, this);
-        else if (RTFS_IS_FILE(nextPath.m_fMode))
-            m_pNextPathMsg = new DnDHGSendFilePrivate(nextPath.m_strHostPath, nextPath.m_strGuestPath, nextPath.m_fMode, nextPath.m_cbSize, &DnDHGSendDataMessage::progressCallback, this);
-        else
-            AssertMsgFailedReturn(("type '%d' is not supported for path '%s'", nextPath.m_fMode, nextPath.m_strHostPath.c_str()), VERR_NO_DATA);
-        m_uriList.removeFirst();
-    }
+        try
+        {
+            if (RTFS_IS_DIRECTORY(nextPath.m_fMode))
+                m_pNextPathMsg = new DnDHGSendDirPrivate(nextPath.m_strGuestPath,
+                                                         nextPath.m_fMode, nextPath.m_cbSize,
+                                                         &DnDHGSendDataMessage::progressCallback, this);
+            else if (RTFS_IS_FILE(nextPath.m_fMode))
+                m_pNextPathMsg = new DnDHGSendFilePrivate(nextPath.m_strHostPath, nextPath.m_strGuestPath,
+                                                          nextPath.m_fMode, nextPath.m_cbSize,
+                                                          &DnDHGSendDataMessage::progressCallback, this);
+            else
+                AssertMsgFailedReturn(("type '%d' is not supported for path '%s'",
+                                       nextPath.m_fMode, nextPath.m_strHostPath.c_str()), VERR_NO_DATA);
+
+            m_uriList.removeFirst();
+        }
+        catch(std::bad_alloc &)
+        {
+            rc = VERR_NO_MEMORY;
+        }
+    }
+
     return rc;
 }
@@ -404,6 +449,6 @@
 bool DnDHGSendDataMessage::hasFileUrls(const char *pcszFormat, size_t cbMax) const
 {
-    DO(("format %s\n", pcszFormat));
-    /* text/uri also an official variant? */
+    LogFlowFunc(("format %s\n", pcszFormat));
+    /** @todo text/uri also an official variant? */
     return    RTStrNICmp(pcszFormat, "text/uri-list", cbMax)             == 0
            || RTStrNICmp(pcszFormat, "x-special/gnome-icon-list", cbMax) == 0;
@@ -435,5 +480,5 @@
     m_uriList.append(PathEntry(pcszPath, &pcszPath[cbBaseLen], objInfo.Attr.fMode, cbSize));
     m_cbAll += cbSize;
-    DO(("cbFile: %u\n", cbSize));
+    LogFlowFunc(("cbFile: %RU64\n", cbSize));
 
     PRTDIR hDir;
@@ -518,5 +563,5 @@
         && pSelf->m_cbAll)
         rc = pSelf->m_pfnProgressCallback((uint64_t)pSelf->m_cbTransfered * 100 / pSelf->m_cbAll,
-                                          DragAndDropSvc::DND_PROGRESS_RUNNING, pSelf->m_pvProgressUser);
+                                          DragAndDropSvc::DND_PROGRESS_RUNNING, VINF_SUCCESS /* rc */, pSelf->m_pvProgressUser);
 
     return rc;
@@ -530,145 +575,159 @@
 {
     int rc = VINF_SUCCESS;
-    switch (uMsg)
-    {
-        case DragAndDropSvc::HOST_DND_HG_EVT_ENTER:
-        {
-            clear();
-            LogFlowFunc(("HOST_DND_HG_EVT_ENTER\n"));
-            DO(("HOST_DND_HG_EVT_ENTER\n"));
-            /* Verify parameter count and types. */
-            if (   cParms != 7
-                || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
-                || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* x-pos */
-                || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* y-pos */
-                || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* default action */
-                || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* allowed actions */
-                || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
-                || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                m_fOpInProcess = true;
-                DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
-                m_dndMessageQueue.append(pMessage);
-            }
-            break;
-        }
-        case DragAndDropSvc::HOST_DND_HG_EVT_MOVE:
-        {
-            LogFlowFunc(("HOST_DND_HG_EVT_MOVE\n"));
-            DO(("HOST_DND_HG_EVT_MOVE\n"));
-            /* Verify parameter count and types. */
-            if (   cParms != 7
-                || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
-                || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* x-pos */
-                || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* y-pos */
-                || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* default action */
-                || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* allowed actions */
-                || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
-                || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                m_fOpInProcess = true;
-                DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
-                m_dndMessageQueue.append(pMessage);
-            }
-            break;
-        }
-        case DragAndDropSvc::HOST_DND_HG_EVT_LEAVE:
-        {
-            LogFlowFunc(("HOST_DND_HG_EVT_LEAVE\n"));
-            DO(("HOST_DND_HG_EVT_LEAVE\n"));
-
-            /* Verify parameter count and types. */
-            if (cParms != 0)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
-                m_dndMessageQueue.append(pMessage);
-            }
-            m_fOpInProcess = false;
-            break;
-        }
-        case DragAndDropSvc::HOST_DND_HG_EVT_DROPPED:
-        {
-            LogFlowFunc(("HOST_DND_HG_EVT_DROPPED\n"));
-            DO(("HOST_DND_HG_EVT_DROPPED\n"));
-            /* Verify parameter count and types. */
-            if (   cParms != 7
-                || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
-                || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* x-pos */
-                || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* y-pos */
-                || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* default action */
-                || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* allowed actions */
-                || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
-                || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
-                m_dndMessageQueue.append(pMessage);
-            }
-            break;
-        }
-        case DragAndDropSvc::HOST_DND_HG_SND_DATA:
-        {
-            LogFlowFunc(("HOST_DND_HG_SND_DATA\n"));
-            DO(("HOST_DND_HG_SND_DATA\n"));
-
-            /* Verify parameter count and types. */
-            if (   cParms != 5
-                || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
-                || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR   /* format */
-                || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* format size */
-                || paParms[3].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
-                || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* data size */)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                DnDHGSendDataMessage *pMessage = new DnDHGSendDataMessage(uMsg, cParms, paParms, m_pfnProgressCallback, m_pvProgressUser);
-                m_dndMessageQueue.append(pMessage);
-            }
-            break;
-        }
-#ifdef VBOX_WITH_DRAG_AND_DROP_GH
-        case DragAndDropSvc::HOST_DND_GH_REQ_PENDING:
-        {
-            LogFlowFunc(("HOST_DND_GH_REQ_PENDING\n"));
-            DO(("HOST_DND_GH_REQ_PENDING\n"));
-
-            /* Verify parameter count and types. */
-            if (   cParms != 1
-                || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
-                m_dndMessageQueue.append(pMessage);
-            }
-            break;
-        }
-        case DragAndDropSvc::HOST_DND_GH_EVT_DROPPED:
-        {
-            LogFlowFunc(("HOST_DND_GH_EVT_DROPPED\n"));
-            DO(("HOST_DND_GH_EVT_DROPPED\n"));
-
-            /* Verify parameter count and types. */
-            if (   cParms != 3
-                || paParms[0].type != VBOX_HGCM_SVC_PARM_PTR   /* format */
-                || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* format size */
-                || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* action */)
-                rc = VERR_INVALID_PARAMETER;
-            else
-            {
-                DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
-                m_dndMessageQueue.append(pMessage);
-            }
-            break;
-        }
-#endif
-        default: rc = VERR_NOT_IMPLEMENTED; break;
+
+    try
+    {
+        switch (uMsg)
+        {
+            case DragAndDropSvc::HOST_DND_HG_EVT_ENTER:
+            {
+                clear();
+                LogFlowFunc(("HOST_DND_HG_EVT_ENTER\n"));
+
+                /* Verify parameter count and types. */
+                if (   cParms != 7
+                    || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
+                    || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* x-pos */
+                    || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* y-pos */
+                    || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* default action */
+                    || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* allowed actions */
+                    || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
+                    || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    m_fOpInProcess = true;
+                    DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
+                    m_dndMessageQueue.append(pMessage);
+                }
+                break;
+            }
+            case DragAndDropSvc::HOST_DND_HG_EVT_MOVE:
+            {
+                LogFlowFunc(("HOST_DND_HG_EVT_MOVE\n"));
+
+                /* Verify parameter count and types. */
+                if (   cParms != 7
+                    || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
+                    || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* x-pos */
+                    || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* y-pos */
+                    || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* default action */
+                    || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* allowed actions */
+                    || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
+                    || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    m_fOpInProcess = true;
+                    DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
+                    m_dndMessageQueue.append(pMessage);
+                }
+                break;
+            }
+            case DragAndDropSvc::HOST_DND_HG_EVT_LEAVE:
+            {
+                LogFlowFunc(("HOST_DND_HG_EVT_LEAVE\n"));
+
+                /* Verify parameter count and types. */
+                if (cParms != 0)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
+                    m_dndMessageQueue.append(pMessage);
+                }
+                m_fOpInProcess = false;
+                break;
+            }
+            case DragAndDropSvc::HOST_DND_HG_EVT_DROPPED:
+            {
+                LogFlowFunc(("HOST_DND_HG_EVT_DROPPED\n"));
+
+                /* Verify parameter count and types. */
+                if (   cParms != 7
+                    || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
+                    || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* x-pos */
+                    || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* y-pos */
+                    || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* default action */
+                    || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* allowed actions */
+                    || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
+                    || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* size */)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
+                    m_dndMessageQueue.append(pMessage);
+                }
+                break;
+            }
+            case DragAndDropSvc::HOST_DND_HG_SND_DATA:
+            {
+                LogFlowFunc(("HOST_DND_HG_SND_DATA\n"));
+
+                /* Verify parameter count and types. */
+                if (   cParms != 5
+                    || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */
+                    || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR   /* format */
+                    || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* format size */
+                    || paParms[3].type != VBOX_HGCM_SVC_PARM_PTR   /* data */
+                    || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* data size */)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    DnDHGSendDataMessage *pMessage = new DnDHGSendDataMessage(uMsg, cParms, paParms, m_pfnProgressCallback, m_pvProgressUser);
+                    m_dndMessageQueue.append(pMessage);
+                }
+                break;
+            }
+    #ifdef VBOX_WITH_DRAG_AND_DROP_GH
+            case DragAndDropSvc::HOST_DND_GH_REQ_PENDING:
+            {
+                LogFlowFunc(("HOST_DND_GH_REQ_PENDING\n"));
+
+                /* Verify parameter count and types. */
+                if (   cParms != 1
+                    || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* screen id */)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    DnDGenericMessage *pMessage = new DnDGenericMessage(uMsg, cParms, paParms);
+                    m_dndMessageQueue.append(pMessage);
+                }
+                break;
+            }
+            case DragAndDropSvc::HOST_DND_GH_EVT_DROPPED:
+            {
+                LogFlowFunc(("HOST_DND_GH_EVT_DROPPED\n"));
+
+                /* Verify parameter count and types. */
+                if (   cParms != 3
+                    || paParms[0].type != VBOX_HGCM_SVC_PARM_PTR   /* format */
+                    || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* format size */
+                    || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* action */)
+                    rc = VERR_INVALID_PARAMETER;
+                else
+                {
+                    try
+                    {
+                        DnDGenericMessage *pMessage
+                            = new DnDGenericMessage(uMsg, cParms, paParms);
+                        m_dndMessageQueue.append(pMessage);
+                    }
+                    catch(std::bad_alloc &)
+                    {
+                        rc = VERR_NO_MEMORY;
+                    }
+                }
+                break;
+            }
+    #endif
+            default:
+                rc = VERR_NOT_IMPLEMENTED;
+                break;
+        }
+    }
+    catch(std::bad_alloc &)
+    {
+        rc = VERR_NO_MEMORY;
     }
 
@@ -710,5 +769,5 @@
     }
 
-    DO(("next msg info: %d %d %Rrc\n", *puMsg, *pcParms, rc));
+    LogFlowFunc(("Returning puMsg=%RU32, pcParms=%RU32, rc=%Rrc\n", *puMsg, *pcParms, rc));
     return rc;
 }
@@ -716,9 +775,15 @@
 int DnDManager::nextMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
 {
+    LogFlowFunc(("uMsg=%RU32, cParms=%RU32\n", uMsg, cParms));
+
     if (!m_pCurMsg)
     {
         /* Check for pending messages in our queue. */
         if (m_dndMessageQueue.isEmpty())
+        {
+            LogFlowFunc(("Message queue is empty, returning\n"));
             return VERR_NO_DATA;
+        }
+
         m_pCurMsg = m_dndMessageQueue.first();
         m_dndMessageQueue.removeFirst();
@@ -727,34 +792,51 @@
     /* Fetch the current message info */
     int rc = m_pCurMsg->currentMessage(uMsg, cParms, paParms);
-    /* If this message not provide any additional sub messages, clear it. */
+    /* If this message doesn't provide any additional sub messages, clear it. */
     if (!m_pCurMsg->isMessageWaiting())
+    {
+        delete m_pCurMsg;
+        m_pCurMsg = NULL;
+    }
+
+    /*
+     * If there was an error handling the current message or the user has canceled
+     * the operation, we need to cleanup all pending events and inform the progress
+     * callback about our exit.
+     */
+    if (   RT_FAILURE(rc)
+        && m_pfnProgressCallback)
+    {
+        /* Clear any pending messages. */
+        clear();
+
+        /* Create a new cancel message to inform the guest + call
+         * the host whether the current transfer was canceled or aborted
+         * due to an error. */
+        try
+        {
+            Assert(!m_pCurMsg);
+            m_pCurMsg = new DnDHGCancelMessage();
+            m_pfnProgressCallback(100 /* Percent */,
+                                    rc == VERR_CANCELLED
+                                  ? DragAndDropSvc::DND_PROGRESS_CANCELLED
+                                  : DragAndDropSvc::DND_PROGRESS_ERROR, rc, m_pvProgressUser);
+        }
+        catch(std::bad_alloc &)
+        {
+            rc = VERR_NO_MEMORY;
+        }
+    }
+
+    LogFlowFunc(("Message processed with rc=%Rrc\n", rc));
+    return rc;
+}
+
+void DnDManager::clear()
+{
+    if (m_pCurMsg)
     {
         delete m_pCurMsg;
         m_pCurMsg = 0;
     }
-
-    /* If the user has canceled the operation, we need to cleanup all pending
-     * events and inform the progress callback about our successful cleanup. */
-    if (   rc == VERR_CANCELLED
-        && m_pfnProgressCallback)
-    {
-        /* Clear any pending messages */
-        clear();
-        /* Create a new cancel message to inform the guest. */
-        m_pCurMsg = new DnDHGCancelMessage();
-        m_pfnProgressCallback(100, DragAndDropSvc::DND_PROGRESS_CANCELLED, m_pvProgressUser);
-    }
-
-    DO(("next msg: %d %d %Rrc\n", uMsg, cParms, rc));
-    return rc;
-}
-
-void DnDManager::clear()
-{
-    if (m_pCurMsg)
-    {
-        delete m_pCurMsg;
-        m_pCurMsg = 0;
-    }
     while (!m_dndMessageQueue.isEmpty())
     {
Index: /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h
===================================================================
--- /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h	(revision 49890)
+++ /trunk/src/VBox/HostServices/DragAndDrop/dndmanager.h	(revision 49891)
@@ -24,5 +24,5 @@
 #include <iprt/cpp/list.h>
 
-typedef DECLCALLBACK(int) FNDNDPROGRESS(unsigned uPercentage, uint32_t uState, void *pvUser);
+typedef DECLCALLBACK(int) FNDNDPROGRESS(unsigned uPercentage, uint32_t uState, int rc, void *pvUser);
 typedef FNDNDPROGRESS *PFNDNDPROGRESS;
 
@@ -168,5 +168,5 @@
       , m_pvProgressUser(pvProgressUser)
     {}
-    ~DnDManager()
+    virtual ~DnDManager()
     {
         clear();
Index: /trunk/src/VBox/HostServices/DragAndDrop/service.cpp
===================================================================
--- /trunk/src/VBox/HostServices/DragAndDrop/service.cpp	(revision 49890)
+++ /trunk/src/VBox/HostServices/DragAndDrop/service.cpp	(revision 49891)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -55,11 +55,10 @@
  *   Header Files                                                             *
  ******************************************************************************/
-#define LOG_GROUP LOG_GROUP_HGCM
+#ifdef LOG_GROUP
+ #undef LOG_GROUP
+#endif
+#define LOG_GROUP LOG_GROUP_GUEST_DND
 
 #include "dndmanager.h"
-
-//# define DO(s) RTPrintf s
-#define DO(s) do {} while(0)
-//#define DO(s) Log s
 
 /******************************************************************************
@@ -88,5 +87,5 @@
     int  hostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
 
-    static DECLCALLBACK(int) progressCallback(unsigned uPercentage, uint32_t uState, void *pvUser);
+    static DECLCALLBACK(int) progressCallback(uint32_t uPercentage, uint32_t uState, int rc, void *pvUser);
     int      hostMessage(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
     void     modeSet(uint32_t u32Mode);
@@ -128,5 +127,4 @@
 {
     LogFlowFunc(("New client (%ld) connected\n", u32ClientID));
-    DO(("New client (%ld) connected\n", u32ClientID));
     if (m_cClients < UINT32_MAX)
         m_cClients++;
@@ -173,15 +171,13 @@
 void DragAndDropService::guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
 {
+    LogFlowFunc(("u32ClientID=%RU32, u32Function=%RU32, cParms=%RU32\n",
+                 u32ClientID, u32Function, cParms));
+
     int rc = VINF_SUCCESS;
-    LogFlowFunc(("u32ClientID = %d, fn = %d, cParms = %d, pparms = %d\n",
-                 u32ClientID, u32Function, cParms, paParms));
-//    RTPrintf("u32ClientID = %d, fn = %d, cParms = %d, pparms = %d\n",
-//                 u32ClientID, u32Function, cParms, paParms);
-
     switch (u32Function)
     {
         case DragAndDropSvc::GUEST_DND_GET_NEXT_HOST_MSG:
         {
-            DO(("GUEST_DND_GET_NEXT_HOST_MSG\n"));
+            LogFlowFunc(("GUEST_DND_GET_NEXT_HOST_MSG\n"));
             if (   cParms != 3
                 || paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* message */
@@ -203,9 +199,9 @@
         case DragAndDropSvc::GUEST_DND_HG_ACK_OP:
         {
-            DO(("GUEST_DND_HG_ACK_OP\n"));
+            LogFlowFunc(("GUEST_DND_HG_ACK_OP\n"));
             if (   modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_HOST_TO_GUEST)
             {
-                DO(("=> ignoring!\n"));
+                LogFlowFunc(("=> ignoring!\n"));
                 break;
             }
@@ -227,9 +223,9 @@
         case DragAndDropSvc::GUEST_DND_HG_REQ_DATA:
         {
-            DO(("GUEST_DND_HG_REQ_DATA\n"));
+            LogFlowFunc(("GUEST_DND_HG_REQ_DATA\n"));
             if (   modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_HOST_TO_GUEST)
             {
-                DO(("=> ignoring!\n"));
+                LogFlowFunc(("=> ignoring!\n"));
                 break;
             }
@@ -257,9 +253,9 @@
         case DragAndDropSvc::GUEST_DND_GH_ACK_PENDING:
         {
-            DO(("GUEST_DND_GH_ACK_PENDING\n"));
+            LogFlowFunc(("GUEST_DND_GH_ACK_PENDING\n"));
             if (   modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
             {
-                DO(("=> ignoring!\n"));
+                LogFlowFunc(("=> ignoring!\n"));
                 break;
             }
@@ -285,9 +281,9 @@
         case DragAndDropSvc::GUEST_DND_GH_SND_DATA:
         {
-            DO(("GUEST_DND_GH_SND_DATA\n"));
+            LogFlowFunc(("GUEST_DND_GH_SND_DATA\n"));
             if (   modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
             {
-                DO(("=> ignoring\n"));
+                LogFlowFunc(("=> ignoring\n"));
                 break;
             }
@@ -310,9 +306,9 @@
         case DragAndDropSvc::GUEST_DND_GH_EVT_ERROR:
         {
-            DO(("GUEST_DND_GH_EVT_ERROR\n"));
+            LogFlowFunc(("GUEST_DND_GH_EVT_ERROR\n"));
             if (   modeGet() != VBOX_DRAG_AND_DROP_MODE_BIDIRECTIONAL
                 && modeGet() != VBOX_DRAG_AND_DROP_MODE_GUEST_TO_HOST)
             {
-                DO(("=> ignoring!\n"));
+                LogFlowFunc(("=> ignoring!\n"));
                 break;
             }
@@ -338,13 +334,4 @@
             /* All other messages are handled by the DnD manager. */
             rc = m_pManager->nextMessage(u32Function, cParms, paParms);
-            /* Check for error. Buffer overflow is allowed. It signals the
-             * guest to ask for more data in the next event. */
-            if (   RT_FAILURE(rc)
-                && rc != VERR_CANCELLED
-                && rc != VERR_BUFFER_OVERFLOW) /* Buffer overflow is allowed. */
-            {
-                m_clientQueue.append(new HGCM::Client(u32ClientID, callHandle, u32Function, cParms, paParms));
-                rc = VINF_HGCM_ASYNC_EXECUTE;
-            }
             break;
         }
@@ -355,5 +342,5 @@
     if (rc != VINF_HGCM_ASYNC_EXECUTE)
         m_pHelpers->pfnCallComplete(callHandle, rc);
-    DO(("guest call: %Rrc\n", rc));
+    LogFlowFunc(("Returning rc=%Rrc\n", rc));
 }
 
@@ -415,4 +402,6 @@
 int DragAndDropService::hostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
 {
+    LogFlowFunc(("u32Function=%RU32, cParms=%RU32\n", u32Function, cParms));
+
     int rc = VINF_SUCCESS;
     if (u32Function == DragAndDropSvc::HOST_DND_SET_MODE)
@@ -428,8 +417,9 @@
     {
         rc = m_pManager->addMessage(u32Function, cParms, paParms);
-        if (    RT_SUCCESS(rc)
+        if (   RT_SUCCESS(rc)
             && !m_clientQueue.isEmpty())
         {
             HGCM::Client *pClient = m_clientQueue.first();
+            AssertPtr(pClient);
             /* Check if this was a request for getting the next host
              * message. If so, return the message id and the parameter
@@ -437,6 +427,6 @@
             if (pClient->message() == DragAndDropSvc::GUEST_DND_GET_NEXT_HOST_MSG)
             {
-                DO(("client is waiting for next host msg\n"));
-//              rc = m_pManager->nextMessageInfo(&paParms[0].u.uint32, &paParms[1].u.uint32);
+                LogFlowFunc(("Client %RU32 is waiting for next host msg\n", pClient->clientId()));
+
                 uint32_t uMsg1;
                 uint32_t cParms1;
@@ -463,5 +453,5 @@
 }
 
-DECLCALLBACK(int) DragAndDropService::progressCallback(unsigned uPercentage, uint32_t uState, void *pvUser)
+DECLCALLBACK(int) DragAndDropService::progressCallback(uint32_t uPercentage, uint32_t uState, int rc, void *pvUser)
 {
     AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
@@ -471,9 +461,11 @@
     if (pSelf->m_pfnHostCallback)
     {
-        DO(("GUEST_DND_HG_EVT_PROGRESS %u\n", uPercentage));
+        LogFlowFunc(("GUEST_DND_HG_EVT_PROGRESS: uPercentage=%RU32, uState=%RU32, rc=%Rrc\n",
+                     uPercentage, uState, rc));
         DragAndDropSvc::VBOXDNDCBHGEVTPROGRESSDATA data;
         data.hdr.u32Magic = DragAndDropSvc::CB_MAGIC_DND_HG_EVT_PROGRESS;
         data.uPercentage  = uPercentage;
         data.uState       = uState;
+        data.rc           = rc;
 
         return pSelf->m_pfnHostCallback(pSelf->m_pvHostData, DragAndDropSvc::GUEST_DND_HG_EVT_PROGRESS, &data, sizeof(data));
Index: /trunk/src/VBox/Main/src-client/GuestDnDImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestDnDImpl.cpp	(revision 49890)
+++ /trunk/src/VBox/Main/src-client/GuestDnDImpl.cpp	(revision 49891)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2011-2012 Oracle Corporation
+ * Copyright (C) 2011-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -29,4 +29,10 @@
 # include <VBox/HostServices/DragAndDropSvc.h>
 
+# ifdef LOG_GROUP
+ # undef LOG_GROUP
+# endif
+# define LOG_GROUP LOG_GROUP_GUEST_DND
+# include <VBox/log.h>
+
 # include <iprt/stream.h>
 # include <iprt/semaphore.h>
@@ -48,16 +54,16 @@
  *    of it to the Main IGuest interface (see UIDnDHandler.cpp).
  * 2. Main: Public interface for doing Drag and Drop. Also manage the IProgress
- *    interfaces for blocking the caller by showing a progress dialog. (see
- *    this file)
+ *    interfaces for blocking the caller by showing a progress dialog (see
+ *    this file).
  * 3. HGCM service: Handle all messages from the host to the guest at once and
- *    encapsulate the internal communication details. (see dndmanager.cpp and
- *    friends)
+ *    encapsulate the internal communication details (see dndmanager.cpp and
+ *    friends).
  * 4. Guest additions: Split into the platform neutral part (see
  *    VBoxGuestR3LibDragAndDrop.cpp) and the guest OS specific parts.
  *    Receive/send message from/to the HGCM service and does all guest specific
- *    operations. Currently only X11 is supported. (see draganddrop.cpp within
- *    VBoxClient)
- *
- * Host  -> Guest:
+ *    operations. Currently only X11 is supported (see draganddrop.cpp within
+ *    VBoxClient).
+ *
+ * Host -> Guest:
  * 1. There are DnD Enter, Move, Leave events which are send exactly like this
  *    to the guest. The info includes the pos, mimetypes and allowed actions.
@@ -86,6 +92,6 @@
  * Dropping of a directory, means recursively transferring _all_ the content.
  *
- * Directories and files are placed into a public visible user directory on the
- * guest (~/Documents/VirtualBox Dropped Files). We can't delete them after the
+ * Directories and files are placed into the user's temporary directory on the
+ * guest (e.g. /tmp/VirtualBox Dropped Files). We can't delete them after the
  * DnD operation, because we didn't know what the DnD target does with it. E.g.
  * it could just be opened in place. This could lead ofc to filling up the disk
@@ -111,22 +117,4 @@
  * Cancel is supported in both directions and cleans up all previous steps
  * (thats is: deleting already transfered dirs/files).
- *
- * There are a lot of DO (debug output) calls in the code. This could be
- * disabled, but should be removed (or replaced by Log calls) when this is
- * nearly finished.
- *
- * For Windows guests there could be different communication become necessary.
- * So the current interface isn't set in stone and should be made public only,
- * after someone had deeply looked into the Win guest support. See
- * http://www.catch22.net/tuts/dragdrop for a start.
- *
- * How to test:
- * First set VBOX_WITH_DRAG_AND_DROP=1 in LocalConfig.kmk. The best is if the
- * host match the guest OS arch. Just build the tree and point a shared folder
- * within the guest to the additions subfolder in bin. Start the guest and
- * execute ./VBoxClient --dragandrop --nodaemon within this shared folder. You
- * should now be able of dragging text or files to the guest. I used a 64bit
- * Linux for both the host and the guest. If the archs don't match, you need to
- * first setup a build environment in the guest ofc.
  *
  * In general I propose the following changes in the VBox HGCM infrastructure
@@ -152,5 +140,5 @@
  * Todo:
  * - Dragging out of the guest (partly done)
- *   - ESC doesn't really work
+ *   - ESC doesn't really work (on Windows guests it's already implemented)
  *   - transfer of URIs (that is the files and patching of the data)
  *   - testing in a multi monitor setup
@@ -230,5 +218,5 @@
 
     void adjustCoords(ULONG uScreenId, ULONG *puX, ULONG *puY) const;
-    void hostCall(const char* psczFunction, uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const;
+    void hostCall(uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const;
 
     /* Static helper */
@@ -254,4 +242,6 @@
 /* What mime-types are supported by VirtualBox.
  * Note: If you add something here, make sure you test it with all guest OS's!
+ ** @todo Make this MIME list configurable / extendable (by extra data?). Currently
+ *        this is done hardcoded on every guest platform (POSIX/Windows).
  */
 /* static */
@@ -296,5 +286,9 @@
 int DnDGuestResponse::waitForGuestResponse()
 {
-    return RTSemEventWait(m_EventSem, 300);
+    int vrc = RTSemEventWait(m_EventSem, 300);
+#ifdef DEBUG_andy
+    LogFlowFunc(("rc=%Rrc\n", vrc));
+#endif
+    return vrc;
 }
 
@@ -340,32 +334,41 @@
 int DnDGuestResponse::setProgress(unsigned uPercentage, uint32_t uState, int rcOp /* = VINF_SUCCESS */)
 {
+    LogFlowFunc(("uPercentage=%RU32, uState=%ld, rcOp=%Rrc\n", uPercentage, uState, rcOp));
+
     int vrc = VINF_SUCCESS;
-    HRESULT rc;
     if (!m_progress.isNull())
     {
         BOOL fCompleted;
-        rc = m_progress->COMGETTER(Completed)(&fCompleted);
+        HRESULT rc = m_progress->COMGETTER(Completed)(&fCompleted);
         if (!fCompleted)
         {
             if (uState == DragAndDropSvc::DND_PROGRESS_ERROR)
+            {
                 rc = m_progress->notifyComplete(E_FAIL,
                                                 COM_IIDOF(IGuest),
                                                 m_parent->getComponentName(),
                                                 m_parent->tr("Guest error (%Rrc)"), rcOp);
+            }
             else if (uState == DragAndDropSvc::DND_PROGRESS_CANCELLED)
-                rc = m_progress->notifyComplete(S_OK);
-            else
+            {
+                rc = m_progress->Cancel();
+                vrc = VERR_CANCELLED;
+            }
+            else /* uState == DragAndDropSvc::DND_PROGRESS_RUNNING */
             {
                 rc = m_progress->SetCurrentOperationProgress(uPercentage);
+#ifndef DEBUG_andy
+                Assert(SUCCEEDED(rc));
+#endif
                 if (   uState      == DragAndDropSvc::DND_PROGRESS_COMPLETE
                     || uPercentage >= 100)
                     rc = m_progress->notifyComplete(S_OK);
             }
+#ifndef DEBUG_andy
+            Assert(SUCCEEDED(rc));
+#endif
         }
-        BOOL fCanceled = FALSE;
-        rc = m_progress->COMGETTER(Canceled)(&fCanceled);
-        if (fCanceled)
-            vrc = VERR_CANCELLED;
-    }
+    }
+
     return vrc;
 }
@@ -391,7 +394,7 @@
 }
 
-void GuestDnDPrivate::hostCall(const char* psczFunction, uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const
-{
-    VMMDev *vmmDev = 0;
+void GuestDnDPrivate::hostCall(uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const
+{
+    VMMDev *vmmDev = NULL;
     {
         /* Make sure mParent is valid, so set the read lock while using.
@@ -409,5 +412,5 @@
                           p->tr("VMM device is not available (is the VM running?)"));
 
-    LogFlowFunc(("hgcmHostCall msg=%s; numParms=%u\n", psczFunction, u32Function));
+    LogFlowFunc(("hgcmHostCall msg=%RU32, numParms=%RU32\n", u32Function, cParms));
     int vrc = vmmDev->hgcmHostCall("VBoxDragAndDropSvc",
                                    u32Function,
@@ -576,6 +579,5 @@
         paParms[i++].setUInt32(strFormats.length() + 1);
 
-        d->hostCall("HOST_DND_HG_EVT_ENTER",
-                    DragAndDropSvc::HOST_DND_HG_EVT_ENTER,
+        d->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_ENTER,
                     i,
                     paParms);
@@ -588,4 +590,5 @@
         /* Copy the response info */
         *pResultAction = d->toMainAction(pDnD->defAction());
+        LogFlowFunc(("*pResultAction=%ld\n", *pResultAction));
     }
     catch (HRESULT rc2)
@@ -636,6 +639,5 @@
         paParms[i++].setUInt32(strFormats.length() + 1);
 
-        d->hostCall("HOST_DND_HG_EVT_MOVE",
-                    DragAndDropSvc::HOST_DND_HG_EVT_MOVE,
+        d->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_MOVE,
                     i,
                     paParms);
@@ -648,4 +650,5 @@
         /* Copy the response info */
         *pResultAction = d->toMainAction(pDnD->defAction());
+        LogFlowFunc(("*pResultAction=%ld\n", *pResultAction));
     }
     catch (HRESULT rc2)
@@ -666,6 +669,5 @@
     try
     {
-        d->hostCall("HOST_DND_HG_EVT_LEAVE",
-                    DragAndDropSvc::HOST_DND_HG_EVT_LEAVE,
+        d->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_LEAVE,
                     0,
                     NULL);
@@ -722,6 +724,5 @@
         paParms[i++].setUInt32(strFormats.length() + 1);
 
-        d->hostCall("HOST_DND_HG_EVT_DROPPED",
-                    DragAndDropSvc::HOST_DND_HG_EVT_DROPPED,
+        d->hostCall(DragAndDropSvc::HOST_DND_HG_EVT_DROPPED,
                     i,
                     paParms);
@@ -735,4 +736,6 @@
         *pResultAction = d->toMainAction(pDnD->defAction());
         Bstr(pDnD->format()).cloneTo(pstrFormat);
+
+        LogFlowFunc(("*pResultAction=%ld\n", *pResultAction));
     }
     catch (HRESULT rc2)
@@ -768,6 +771,5 @@
         pDnD->resetProgress(p);
 
-        d->hostCall("HOST_DND_HG_SND_DATA",
-                    DragAndDropSvc::HOST_DND_HG_SND_DATA,
+        d->hostCall(DragAndDropSvc::HOST_DND_HG_SND_DATA,
                     i,
                     paParms);
@@ -801,6 +803,5 @@
         paParms[i++].setUInt32(uScreenId);
 
-        d->hostCall("HOST_DND_GH_REQ_PENDING",
-                    DragAndDropSvc::HOST_DND_GH_REQ_PENDING,
+        d->hostCall(DragAndDropSvc::HOST_DND_GH_REQ_PENDING,
                     i,
                     paParms);
@@ -855,6 +856,5 @@
         pDnD->resetProgress(p);
 
-        d->hostCall("HOST_DND_GH_EVT_DROPPED",
-                    DragAndDropSvc::HOST_DND_GH_EVT_DROPPED,
+        d->hostCall(DragAndDropSvc::HOST_DND_GH_EVT_DROPPED,
                     i,
                     paParms);
@@ -902,4 +902,7 @@
 DECLCALLBACK(int) GuestDnD::notifyGuestDragAndDropEvent(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms)
 {
+    LogFlowFunc(("pvExtension=%p, u32Function=%RU32, pvParms=%p, cbParms=%RU32\n",
+                 pvExtension, u32Function, pvParms, cbParms));
+
     ComObjPtr<Guest> pGuest = reinterpret_cast<Guest*>(pvExtension);
     if (!pGuest->m_pGuestDnD)
@@ -909,6 +912,6 @@
     const ComObjPtr<Guest> &p = d->p;
 
-    DnDGuestResponse *pDnD = d->response();
-    if (pDnD == NULL)
+    DnDGuestResponse *pResp = d->response();
+    if (pResp == NULL)
         return VERR_INVALID_PARAMETER;
 
@@ -922,6 +925,6 @@
             AssertReturn(sizeof(DragAndDropSvc::VBOXDNDCBHGACKOPDATA) == cbParms, VERR_INVALID_PARAMETER);
             AssertReturn(DragAndDropSvc::CB_MAGIC_DND_HG_ACK_OP == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
-            pDnD->setDefAction(pCBData->uAction);
-            rc = pDnD->notifyAboutGuestResponse();
+            pResp->setDefAction(pCBData->uAction);
+            rc = pResp->notifyAboutGuestResponse();
             break;
         }
@@ -932,6 +935,6 @@
             AssertReturn(sizeof(DragAndDropSvc::VBOXDNDCBHGREQDATADATA) == cbParms, VERR_INVALID_PARAMETER);
             AssertReturn(DragAndDropSvc::CB_MAGIC_DND_HG_REQ_DATA == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
-            pDnD->setFormat(pCBData->pszFormat);
-            rc = pDnD->notifyAboutGuestResponse();
+            pResp->setFormat(pCBData->pszFormat);
+            rc = pResp->notifyAboutGuestResponse();
             break;
         }
@@ -942,5 +945,5 @@
             AssertReturn(sizeof(DragAndDropSvc::VBOXDNDCBHGEVTPROGRESSDATA) == cbParms, VERR_INVALID_PARAMETER);
             AssertReturn(DragAndDropSvc::CB_MAGIC_DND_HG_EVT_PROGRESS == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
-            rc = pDnD->setProgress(pCBData->uPercentage, pCBData->uState);
+            rc = pResp->setProgress(pCBData->uPercentage, pCBData->uState, pCBData->rc);
             break;
         }
@@ -952,8 +955,8 @@
             AssertReturn(sizeof(DragAndDropSvc::VBOXDNDCBGHACKPENDINGDATA) == cbParms, VERR_INVALID_PARAMETER);
             AssertReturn(DragAndDropSvc::CB_MAGIC_DND_GH_ACK_PENDING == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
-            pDnD->setFormat(pCBData->pszFormat);
-            pDnD->setDefAction(pCBData->uDefAction);
-            pDnD->setAllActions(pCBData->uAllActions);
-            rc = pDnD->notifyAboutGuestResponse();
+            pResp->setFormat(pCBData->pszFormat);
+            pResp->setDefAction(pCBData->uDefAction);
+            pResp->setAllActions(pCBData->uAllActions);
+            rc = pResp->notifyAboutGuestResponse();
             break;
         }
@@ -965,11 +968,11 @@
             AssertReturn(DragAndDropSvc::CB_MAGIC_DND_GH_SND_DATA == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
             uint32_t cbCurSize = 0;
-            pDnD->addData(pCBData->pvData, pCBData->cbData, &cbCurSize);
-            rc = pDnD->setProgress(100.0 / pCBData->cbAllSize * cbCurSize, (pCBData->cbAllSize == cbCurSize ? DragAndDropSvc::DND_PROGRESS_COMPLETE : DragAndDropSvc::DND_PROGRESS_RUNNING));
+            pResp->addData(pCBData->pvData, pCBData->cbData, &cbCurSize);
+            rc = pResp->setProgress(100.0 / pCBData->cbAllSize * cbCurSize, (pCBData->cbAllSize == cbCurSize ? DragAndDropSvc::DND_PROGRESS_COMPLETE : DragAndDropSvc::DND_PROGRESS_RUNNING));
             /* Todo: for now we instantly confirm the cancel. Check if the
              * guest should first clean up stuff itself and than really confirm
              * the cancel request by an extra message. */
             if (rc == VERR_CANCELLED)
-                pDnD->setProgress(100, DragAndDropSvc::DND_PROGRESS_CANCELLED);
+                pResp->setProgress(100, DragAndDropSvc::DND_PROGRESS_CANCELLED);
             break;
         }
@@ -981,12 +984,15 @@
             AssertReturn(DragAndDropSvc::CB_MAGIC_DND_GH_EVT_ERROR == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
             /* Cleanup */
-            pDnD->resetData();
-            rc = pDnD->setProgress(100, DragAndDropSvc::DND_PROGRESS_ERROR, pCBData->rc);
+            pResp->resetData();
+            rc = pResp->setProgress(100, DragAndDropSvc::DND_PROGRESS_ERROR, pCBData->rc);
             break;
         }
 #endif /* VBOX_WITH_DRAG_AND_DROP_GH */
-        default: AssertMsgFailedReturn(("Function %u not recognized!\n", u32Function), VERR_INVALID_PARAMETER); break;
-    }
-
+        default:
+            AssertMsgFailedReturn(("Function %RU32 not supported\n", u32Function), VERR_NOT_SUPPORTED);
+            break;
+    }
+
+    LogFlowFunc(("Returning rc=%Rrc\n", rc));
     return rc;
 }
Index: /trunk/tools/bin/gen-slickedit-workspace.sh
===================================================================
--- /trunk/tools/bin/gen-slickedit-workspace.sh	(revision 49890)
+++ /trunk/tools/bin/gen-slickedit-workspace.sh	(revision 49891)
@@ -146,5 +146,5 @@
             ;;
     esac
-    if test -n "$3"; 
+    if test -n "$3";
     then
         MY_FOLDER="$1-$3.lst"
@@ -225,13 +225,13 @@
             if test -d "${f}";
             then
-                if test -z "${MY_OPT_USE_WILDCARDS}"; 
+                if test -z "${MY_OPT_USE_WILDCARDS}";
                 then
                     my_sub_tree "${MY_FILE}" "${f}"
                 else
                     case "${f}" in
-                        ${MY_ROOT_DIR}/include*) 
+                        ${MY_ROOT_DIR}/include*)
                             my_sub_tree "${MY_FILE}" "${f}" "Headers"
                             ;;
-                        *)  my_wildcard "${MY_FILE}" "${f}" 
+                        *)  my_wildcard "${MY_FILE}" "${f}"
                             ;;
                     esac
@@ -257,5 +257,5 @@
     if test -s "${MY_FILE}-Headers.lst";
     then
-        if test -z "${MY_OPT_USE_WILDCARDS}"; 
+        if test -z "${MY_OPT_USE_WILDCARDS}";
         then
             echo '        <Folder Name="Headers"  Filters="*.h;*.hpp">' >> "${MY_FILE}"
@@ -908,4 +908,5 @@
 # src/VBox/HostServices
 my_generate_project "GuestCntl"     "src/VBox/HostServices/GuestControl"    --begin-incs "include" "src/VBox/HostServices/GuestControl"     --end-includes "src/VBox/HostServices/GuestControl"
+my_generate_project "DragAndDrop"   "src/VBox/HostServices/DragAndDrop"     --begin-incs "include" "src/VBox/HostServices/DragAndDrop"      --end-includes "src/VBox/HostServices/DragAndDrop"
 my_generate_project "GuestProps"    "src/VBox/HostServices/GuestProperties" --begin-incs "include" "src/VBox/HostServices/GuestProperties"  --end-includes "src/VBox/HostServices/GuestProperties"
 my_generate_project "ShClip-HS"     "src/VBox/HostServices/SharedClipboard" --begin-incs "include" "src/VBox/HostServices/SharedClipboard"  --end-includes "src/VBox/HostServices/SharedClipboard"
