Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 41856)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 41858)
@@ -1863,4 +1863,18 @@
 }
 
+static D3DQUERYTYPE vboxDDI2D3DQueryType(D3DDDIQUERYTYPE enmType)
+{
+    return (D3DQUERYTYPE)enmType;
+}
+
+static DWORD vboxDDI2D3DIssueQueryFlags(D3DDDI_ISSUEQUERYFLAGS Flags)
+{
+    DWORD fFlags = 0;
+    if (Flags.Begin)
+        fFlags |= D3DISSUE_BEGIN;
+    if (Flags.End)
+        fFlags |= D3DISSUE_END;
+    return fFlags;
+}
 
 /******/
@@ -6343,27 +6357,30 @@
     VBOXDISP_DDI_PROLOGUE_DEV(hDevice);
     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-//    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
-//    Assert(pDevice);
-//    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
+
+    IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
     HRESULT hr = S_OK;
-    if (pData->QueryType == D3DDDIQUERYTYPE_EVENT)
-    {
-        PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)RTMemAllocZ(sizeof (VBOXWDDMDISP_QUERY));
-        Assert(pQuery);
-        if (pQuery)
-        {
-            pQuery->enmType = pData->QueryType;
-            pData->hQuery = pQuery;
-        }
-        else
-        {
-            hr = E_OUTOFMEMORY;
-        }
-    }
-    else
-    {
-        Assert(0);
-        hr = E_FAIL;
-    }
+    PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)RTMemAllocZ(sizeof (VBOXWDDMDISP_QUERY));
+    if (!pQuery)
+    {
+        WARN(("RTMemAllocZ failed"));
+        return E_OUTOFMEMORY;
+    }
+
+    hr = pDevice9If->CreateQuery(vboxDDI2D3DQueryType(pData->QueryType), &pQuery->pQueryIf);
+    if (FAILED(hr))
+    {
+        WARN(("CreateQuery failed, hr 0x%x", hr));
+        RTMemFree(pQuery);
+        return hr;
+    }
+
+    Assert(hr == S_OK);
+
+    pQuery->enmType = pData->QueryType;
+    pData->hQuery = pQuery;
+
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     return hr;
@@ -6374,10 +6391,11 @@
     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     HRESULT hr = S_OK;
-//    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
-//    Assert(pDevice);
-//    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
 
     PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)hQuery;
     Assert(pQuery);
+    pQuery->pQueryIf->Release();
     RTMemFree(pQuery);
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
@@ -6389,11 +6407,15 @@
     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     HRESULT hr = S_OK;
-//    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
-//    Assert(pDevice);
-//    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
 
     PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)pData->hQuery;
     Assert(pQuery);
     pQuery->fQueryState.Value |= pData->Flags.Value;
+    hr = pQuery->pQueryIf->Issue(vboxDDI2D3DIssueQueryFlags(pData->Flags));
+    if (hr != S_OK)
+        WARN(("Issue failed, hr = 0x%x", hr));
+
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     return hr;
@@ -6404,22 +6426,26 @@
     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     HRESULT hr = S_OK;
-//    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
-//    Assert(pDevice);
-//    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
 
     PVBOXWDDMDISP_QUERY pQuery = (PVBOXWDDMDISP_QUERY)pData->hQuery;
     Assert(pQuery);
+    DWORD cbData = pQuery->pQueryIf->GetDataSize();
+#ifdef DEBUG
     switch (pQuery->enmType)
     {
         case D3DDDIQUERYTYPE_EVENT:
-            pQuery->data.bData = TRUE;
-            Assert(pData->pData);
-            *((BOOL*)pData->pData) = TRUE;
+            Assert(cbData == sizeof (BOOL));
             break;
         default:
             Assert(0);
-            hr = E_FAIL;
             break;
     }
+#endif
+    hr = pQuery->pQueryIf->GetData(pData->pData, cbData, 0);
+    if (hr != S_OK)
+        WARN(("GetData failed, hr = 0x%x", hr));
+
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     return hr;
@@ -7562,4 +7588,5 @@
 }
 
+
 HRESULT APIENTRY OpenAdapter(__inout D3DDDIARG_OPENADAPTER*  pOpenData)
 {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h	(revision 41856)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h	(revision 41858)
@@ -293,9 +293,5 @@
     D3DDDIQUERYTYPE enmType;
     D3DDDI_ISSUEQUERYFLAGS fQueryState;
-    union
-    {
-        BOOL bData;
-        UINT u32Data;
-    } data ;
+    IDirect3DQuery9 *pQueryIf;
 } VBOXWDDMDISP_QUERY, *PVBOXWDDMDISP_QUERY;
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 41856)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 41858)
@@ -62,13 +62,11 @@
     }
 
+#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
     {
-#ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
-        ERR("Event query tested from wrong thread\n");
-#else
         WARN("Event query tested from wrong thread\n");
+        return WINED3D_EVENT_QUERY_WRONG_THREAD;
+    }
 #endif
-        return WINED3D_EVENT_QUERY_WRONG_THREAD;
-    }
 
     context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
@@ -115,6 +113,13 @@
     else
     {
+#ifdef VBOX_WITH_WDDM
+        Assert(0);
+        /* doing Flush (rather than Finish) should be enough since we're serialized on the host in any way */
+        wglFlush();
+        ret = WINED3D_EVENT_QUERY_OK;
+#else
         ERR("Event query created despite lack of GL support\n");
         ret = WINED3D_EVENT_QUERY_ERROR;
+#endif
     }
 
