Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h	(revision 46966)
@@ -35,5 +35,5 @@
 
 /* One would increase this whenever definitions in this file are changed */
-#define VBOXVIDEOIF_VERSION 18
+#define VBOXVIDEOIF_VERSION 19
 
 #define VBOXWDDM_NODE_ID_SYSTEM           0
@@ -424,5 +424,5 @@
     VBOXDISP_KMHANDLE hSwapchainKm; /* in, NULL if new is being created */
     VBOXDISP_UMHANDLE hSwapchainUm; /* in, UMD private data */
-    DWORD winHostID;
+    int32_t winHostID;
     RECT Rect;
     UINT u32Reserved;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp	(revision 46966)
@@ -831,12 +831,39 @@
 
     HRESULT hr = pAdapter->D3D.pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, fFlags, &Params.Base, &pDevice9If);
-    if (!SUCCEEDED(hr))
-    {
+    if (SUCCEEDED(hr))
+    {
+        int32_t hostId = 0;
+        hr = pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9GetHostId((IDirect3DDevice9Ex*)pDevice9If, &hostId);
+        if (SUCCEEDED(hr))
+        {
+            Assert(hostId);
+
+            VBOXDISPIFESCAPE Data;
+            Data.escapeCode = VBOXESC_SETCTXHOSTID;
+            Data.u32CmdSpecific = (uint32_t)hostId;
+            D3DDDICB_ESCAPE DdiEscape = {0};
+            DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;
+            DdiEscape.hDevice = pDevice->hDevice;
+        //    DdiEscape.Flags.Value = 0;
+            DdiEscape.pPrivateDriverData = &Data;
+            DdiEscape.PrivateDriverDataSize = sizeof (Data);
+            hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);
+            if (SUCCEEDED(hr))
+            {
+                pDevice->pDevice9If = pDevice9If;
+                return S_OK;
+            }
+            else
+                WARN(("pfnEscapeCb VBOXESC_SETCTXHOSTID failed hr 0x%x", hr));
+        }
+        else
+            WARN(("pfnVBoxWineExD3DDev9GetHostId failed hr 0x%x", hr));
+
+        pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Term((IDirect3DDevice9Ex *)pDevice9If);
+    }
+    else
         WARN(("CreateDevice failed hr 0x%x", hr));
-        return hr;
-    }
-
-    pDevice->pDevice9If = pDevice9If;
-    return S_OK;
-}
-
+
+    return hr;
+}
+
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 46966)
@@ -160,4 +160,11 @@
         {
             WARN(("no VBoxWineExD3DSwapchain9GetHostWinID"));
+            break;
+        }
+
+        pD3D->pfnVBoxWineExD3DDev9GetHostId = (PFNVBOXWINEEXD3DDEV9_GETHOSTID)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9GetHostId");
+        if (!pD3D->pfnVBoxWineExD3DDev9GetHostId)
+        {
+            WARN(("no VBoxWineExD3DDev9GetHostId"));
             break;
         }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h	(revision 46966)
@@ -85,4 +85,6 @@
     PFNVBOXWINEEXD3DSWAPCHAIN9_GETHOSTWINID pfnVBoxWineExD3DSwapchain9GetHostWinID;
 
+    PFNVBOXWINEEXD3DDEV9_GETHOSTID pfnVBoxWineExD3DDev9GetHostId;
+
     /* module handle */
     HMODULE hD3DLib;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp	(revision 46966)
@@ -394,14 +394,25 @@
 NTSTATUS vboxWddmSwapchainCtxEscape(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_CONTEXT pContext, PVBOXDISPIFESCAPE_SWAPCHAININFO pSwapchainInfo, UINT cbSize)
 {
-    Assert((cbSize >= RT_OFFSETOF(VBOXDISPIFESCAPE_SWAPCHAININFO, SwapchainInfo.ahAllocs[0])));
     if (cbSize < RT_OFFSETOF(VBOXDISPIFESCAPE_SWAPCHAININFO, SwapchainInfo.ahAllocs[0]))
+    {
+        WARN(("invalid cbSize1 %d", cbSize));
         return STATUS_INVALID_PARAMETER;
-    Assert(cbSize >= RT_OFFSETOF(VBOXDISPIFESCAPE_SWAPCHAININFO, SwapchainInfo.ahAllocs[pSwapchainInfo->SwapchainInfo.cAllocs]));
+    }
+
     if (cbSize < RT_OFFSETOF(VBOXDISPIFESCAPE_SWAPCHAININFO, SwapchainInfo.ahAllocs[pSwapchainInfo->SwapchainInfo.cAllocs]))
+    {
         return STATUS_INVALID_PARAMETER;
+        WARN(("invalid cbSize2 %d", cbSize));
+    }
 
     if (!pSwapchainInfo->SwapchainInfo.winHostID)
     {
         WARN(("Zero winHostID specified!"));
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    if (!pContext)
+    {
+        WARN(("vboxWddmSwapchainCtxEscape: no context specified"));
         return STATUS_INVALID_PARAMETER;
     }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 46966)
@@ -228,5 +228,5 @@
     VBOXDISP_UMHANDLE hSwapchainUm;
     VBOXDISP_KMHANDLE hSwapchainKm;
-    UINT winHostID;
+    int32_t winHostID;
     BOOLEAN fExposed;
     POINT Pos;
@@ -244,4 +244,5 @@
     UINT  EngineAffinity;
     BOOLEAN fRenderFromShadowDisabled;
+    int32_t hostID;
     uint32_t u32CrConClientID;
     VBOXMP_CRPACKER CrPacker;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 46966)
@@ -4110,4 +4110,41 @@
                 break;
             }
+            case VBOXESC_SETCTXHOSTID:
+            {
+                /* set swapchain information */
+                PVBOXWDDM_CONTEXT pContext = (PVBOXWDDM_CONTEXT)pEscape->hContext;
+                if (!pContext)
+                {
+                    WARN(("VBOXESC_SETCTXHOSTID: no context specified"));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                if (pEscape->PrivateDriverDataSize != sizeof (VBOXDISPIFESCAPE))
+                {
+                    WARN(("VBOXESC_SETCTXHOSTID: invalid data size %d", pEscape->PrivateDriverDataSize));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                int32_t hostID = (int32_t)pEscapeHdr->u32CmdSpecific;
+                if (hostID <= 0)
+                {
+                    WARN(("VBOXESC_SETCTXHOSTID: invalid hostID %d", hostID));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                if (pContext->hostID)
+                {
+                    WARN(("VBOXESC_SETCTXHOSTID: context already has hostID specified"));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                pContext->hostID = hostID;
+                Status = STATUS_SUCCESS;
+                break;
+            }
             case VBOXESC_SWAPCHAININFO:
             {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/d3d9wddm.def
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/d3d9wddm.def	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/d3d9wddm.def	(revision 46966)
@@ -13,5 +13,5 @@
   Direct3DCreate9Ex
   VBoxWineExD3DDev9Flush
-  VBoxWineExD3DDev9FlushToHost
+  VBoxWineExD3DDev9GetHostId
   VBoxWineExD3DDev9Finish
   VBoxWineExD3DDev9CreateTexture
@@ -25,2 +25,3 @@
   VBoxWineExD3DSwapchain9GetHostWinID
   VBoxWineExD3DSurf9SyncToHost
+  VBoxWineExD3DDev9FlushToHost
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/device.c	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/device.c	(revision 46966)
@@ -817,4 +817,18 @@
     wined3d_mutex_lock();
     hr = wined3d_device_finish(device->wined3d_device);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9GetHostId(IDirect3DDevice9Ex *iface, int32_t *pi32Id)
+{
+    struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
+    HRESULT hr;
+
+    TRACE("iface %p, FlushToHost\n", iface);
+
+    wined3d_mutex_lock();
+    hr = wined3d_device_get_host_id(device->wined3d_device, pi32Id);
     wined3d_mutex_unlock();
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/swapchain.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/swapchain.c	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/swapchain.c	(revision 46966)
@@ -307,10 +307,10 @@
 }
 
-VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, DWORD *pID)
-{
-    struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9(iface);
-    HRESULT hr;
-    wined3d_mutex_lock();
-    hr = wined3d_swapchain_get_host_win_id(swapchain->wined3d_swapchain, pID);
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, int32_t *pi32Id)
+{
+    struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9(iface);
+    HRESULT hr;
+    wined3d_mutex_lock();
+    hr = wined3d_swapchain_get_host_win_id(swapchain->wined3d_swapchain, pi32Id);
     wined3d_mutex_unlock();
     return hr;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/vbox/VBoxWineEx.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/vbox/VBoxWineEx.h	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/vbox/VBoxWineEx.h	(revision 46966)
@@ -72,4 +72,7 @@
 typedef FNVBOXWINEEXD3DDEV9_FLUSHTOHOST *PFNVBOXWINEEXD3DDEV9_FLUSHTOHOST;
 
+typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DDEV9_GETHOSTID(IDirect3DDevice9Ex *iface, int32_t *pi32Id);
+typedef FNVBOXWINEEXD3DDEV9_GETHOSTID *PFNVBOXWINEEXD3DDEV9_GETHOSTID;
+
 typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DDEV9_FINISH(IDirect3DDevice9Ex *iface);
 typedef FNVBOXWINEEXD3DDEV9_FINISH *PFNVBOXWINEEXD3DDEV9_FINISH;
@@ -87,5 +90,5 @@
 typedef FNVBOXWINEEXD3DSWAPCHAIN9_PRESENT *PFNVBOXWINEEXD3DSWAPCHAIN9_PRESENT;
 
-typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DSWAPCHAIN9_GETHOSTWINID(IDirect3DSwapChain9 *iface, DWORD *pID);
+typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DSWAPCHAIN9_GETHOSTWINID(IDirect3DSwapChain9 *iface, int32_t *pID);
 typedef FNVBOXWINEEXD3DSWAPCHAIN9_GETHOSTWINID *PFNVBOXWINEEXD3DSWAPCHAIN9_GETHOSTWINID;
 
@@ -127,4 +130,6 @@
 VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9FlushToHost(IDirect3DDevice9Ex *iface); /* flash data to host */
 
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9GetHostId(IDirect3DDevice9Ex *iface, int32_t *pi32Id);
+
 VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Term(IDirect3DDevice9Ex *iface);
 
@@ -139,5 +144,5 @@
                                 IDirect3DSurface9 *surf); /* use the given surface as a frontbuffer content source */
 
-VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, DWORD *pID);
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, int32_t *pi32Id);
 
 typedef struct VBOXWINEEX_D3DPRESENT_PARAMETERS
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/vbox/libWineStub/include/wine/wined3d.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/vbox/libWineStub/include/wine/wined3d.h	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/vbox/libWineStub/include/wine/wined3d.h	(revision 46966)
@@ -2479,8 +2479,11 @@
 HRESULT __cdecl wined3d_device_blt_vol(struct wined3d_device *device, struct wined3d_volume *src, struct wined3d_volume *dst, const struct wined3d_box *pSrcBoxArg, const struct VBOXPOINT3D *pDstPoin3D);
 HRESULT __cdecl wined3d_device_blt_voltex(struct wined3d_device *device, struct wined3d_texture *src, struct wined3d_texture *dst, const struct wined3d_box *pSrcBoxArg, const struct VBOXPOINT3D *pDstPoin3D);
+HRESULT __cdecl wined3d_device_get_host_id(struct wined3d_device *device, int32_t *pid);
+
 HRESULT __cdecl wined3d_surface_get_host_id(struct wined3d_surface *surface, uint32_t *id);
 HRESULT __cdecl wined3d_surface_sync_to_host(struct wined3d_surface *surface);
 
 HRESULT __cdecl wined3d_swapchain_present_rt(struct wined3d_swapchain *swapchain, struct wined3d_surface *rt);
+HRESULT __cdecl wined3d_swapchain_get_host_win_id(struct wined3d_swapchain *swapchain, int32_t *pi32Id);
 #endif
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/device.c	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/device.c	(revision 46966)
@@ -5688,3 +5688,17 @@
 
 }
+
+HRESULT CDECL wined3d_device_get_host_id(struct wined3d_device *device, int32_t *pid)
+{
+    int32_t id = pVBoxGetContextId(device->contexts[0]->glCtx);
+    if (!id)
+    {
+        *pid = 0;
+        ERR("pVBoxGetContextId to get id for context 0x%x", device->contexts[0]->glCtx);
+        return E_FAIL;
+    }
+
+    *pid = id;
+    return WINED3D_OK;
+}
 #endif
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/swapchain.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/swapchain.c	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/swapchain.c	(revision 46966)
@@ -1536,13 +1536,14 @@
 }
 
-HRESULT CDECL wined3d_swapchain_get_host_win_id(struct wined3d_swapchain *swapchain, DWORD *pID)
-{
-    DWORD id = (DWORD)pVBoxGetWindowId(swapchain->hDC);
+HRESULT CDECL wined3d_swapchain_get_host_win_id(struct wined3d_swapchain *swapchain, int32_t *pi32Id)
+{
+    int32_t id = pVBoxGetWindowId(swapchain->hDC);
     if (!id)
     {
+        *pi32Id = 0;
         ERR("failed to get id for hdc 0x%x", swapchain->hDC);
         return E_FAIL;
     }
-    *pID = id;
+    *pi32Id = id;
     return S_OK;
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/wined3d_gl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/wined3d_gl.h	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/wined3d_gl.h	(revision 46966)
@@ -185,4 +185,5 @@
 void (WINAPI *pVBoxFlushToHost)(HGLRC) DECLSPEC_HIDDEN;
 GLint (WINAPI *pVBoxGetWindowId)(HDC)  DECLSPEC_HIDDEN;
+GLint (WINAPI *pVBoxGetContextId)(HGLRC)  DECLSPEC_HIDDEN;
 
 
@@ -192,5 +193,6 @@
         VBOX_USE_FUNC(VBoxCreateContext) \
         VBOX_USE_FUNC(VBoxFlushToHost) \
-        VBOX_USE_FUNC(VBoxGetWindowId)
+        VBOX_USE_FUNC(VBoxGetWindowId) \
+        VBOX_USE_FUNC(VBoxGetContextId)
 
 # define VBOX_GL_EXT_FUNCS_GEN \
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/wined3dwddm.def
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/wined3dwddm.def	(revision 46896)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/wined3dwddm.def	(revision 46966)
@@ -261,2 +261,3 @@
   wined3d_surface_sync_to_host
   wined3d_swapchain_get_host_win_id
+  wined3d_device_get_host_id
