Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk	(revision 29431)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk	(revision 29432)
@@ -79,4 +79,5 @@
 VBoxDispD3D_SOURCES  = \
 	wddm/VBoxDispD3D.cpp \
+    wddm/VBoxDispD3DIf.cpp \
 	wddm/VBoxDispD3D.def \
 	wddm/VBoxDispD3D.rc
@@ -85,4 +86,5 @@
 	$(VBOX_LIB_VBGL_R3)
 VBoxDispD3D_SDKS     = WINDDKWLH
+# VBoxDispD3D_INCS    += ../Wine/include
 
  ifeq ($(KBUILD_TARGET_ARCH), amd64)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 29431)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 29432)
@@ -29,4 +29,5 @@
 
 #include "VBoxDispD3D.h"
+#include "VBoxDispD3DCmn.h"
 
 #ifdef VBOXWDDMDISP_DEBUG
@@ -45,16 +46,9 @@
         case DLL_PROCESS_ATTACH:
         {
-            /* there __try __except are just to ensure the library does not assertion fail in case VBoxGuest is not present
-             * and VbglR3Init / VbglR3Term assertion fail */
-            __try
-            {
-//                LogRel(("VBoxDispD3D: DLL loaded.\n"));
-                RTR3Init();
+            RTR3Init();
+
+            vboxVDbgPrint(("VBoxDispD3D: DLL loaded.\n"));
+
 //                VbglR3Init();
-            }
-            __except (EXCEPTION_CONTINUE_EXECUTION)
-            {
-            }
-
             break;
         }
@@ -62,14 +56,6 @@
         case DLL_PROCESS_DETACH:
         {
-            /* there __try __except are just to ensure the library does not assertion fail in case VBoxGuest is not present
-             * and VbglR3Init / VbglR3Term assertion fail */
-//            __try
-//            {
-//                LogRel(("VBoxDispD3D: DLL unloaded.\n"));
+            vboxVDbgPrint(("VBoxDispD3D: DLL unloaded.\n"));
 //                VbglR3Term();
-//            }
-//            __except (EXCEPTION_CONTINUE_EXECUTION)
-//            {
-//            }
             /// @todo RTR3Term();
             break;
@@ -901,5 +887,5 @@
     vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
 
-//    AssertBreakpoint();
+    AssertBreakpoint();
 
     PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)RTMemAllocZ(sizeof (VBOXWDDMDISP_DEVICE));
@@ -1038,5 +1024,5 @@
     vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
 
-    return E_FAIL;
+    return S_OK;
 }
 
@@ -1045,7 +1031,15 @@
     vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
 
-//    AssertBreakpoint();
-
-    RTMemFree(hAdapter);
+    AssertBreakpoint();
+
+    PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
+    if (pAdapter->pD3D9If)
+    {
+        HRESULT hr = pAdapter->pD3D9If->Release();
+        Assert(hr == S_OK);
+        VBoxDispD3DClose(&pAdapter->D3D);
+    }
+
+    RTMemFree(pAdapter);
 
     vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
@@ -1058,28 +1052,53 @@
     vboxVDbgPrint(("==> "__FUNCTION__"\n"));
 
-//    AssertBreakpoint();
-
+    AssertBreakpoint();
+
+    HRESULT hr = S_OK;
     PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(sizeof (VBOXWDDMDISP_ADAPTER));
     Assert(pAdapter);
-    if (!pAdapter)
+    if (pAdapter)
+    {
+        pAdapter->hAdapter = pOpenData->hAdapter;
+        pAdapter->uIfVersion = pOpenData->Interface;
+        pAdapter->uRtVersion= pOpenData->Version;
+        pAdapter->RtCallbacks = *pOpenData->pAdapterCallbacks;
+
+        pOpenData->hAdapter = pAdapter;
+        pOpenData->pAdapterFuncs->pfnGetCaps = vboxWddmDispGetCaps;
+        pOpenData->pAdapterFuncs->pfnCreateDevice = vboxWddmDispCreateDevice;
+        pOpenData->pAdapterFuncs->pfnCloseAdapter = vboxWddmDispCloseAdapter;
+        pOpenData->DriverVersion = D3D_UMD_INTERFACE_VERSION;
+
+        /* try enable the 3D */
+        hr = VBoxDispD3DOpen(&pAdapter->D3D);
+        Assert(hr == S_OK);
+        if (hr == S_OK)
+        {
+            hr = pAdapter->D3D.pfnDirect3DCreate9Ex(D3D_SDK_VERSION, &pAdapter->pD3D9If);
+            Assert(hr == S_OK);
+            if (hr == S_OK)
+            {
+                vboxVDbgPrint(("<== "__FUNCTION__", SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter));
+                return S_OK;
+            }
+            else
+                vboxVDbgPrintR((__FUNCTION__": pfnDirect3DCreate9Ex failed, hr (%d)\n", hr));
+        }
+        else
+            vboxVDbgPrintR((__FUNCTION__": VBoxDispD3DOpen failed, hr (%d)\n", hr));
+
+        vboxVDbgPrint(("<== "__FUNCTION__", SUCCESS 3D DISABLED, pAdapter (0x%p)\n", pAdapter));
+        return S_OK;
+//        RTMemFree(pAdapter);
+    }
+    else
     {
         vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
-        return E_OUTOFMEMORY;
+        hr = E_OUTOFMEMORY;
     }
 
-    pAdapter->hAdapter = pOpenData->hAdapter;
-    pAdapter->uIfVersion = pOpenData->Interface;
-    pAdapter->uRtVersion= pOpenData->Version;
-    pAdapter->RtCallbacks = *pOpenData->pAdapterCallbacks;
-
-    pOpenData->hAdapter = pAdapter;
-    pOpenData->pAdapterFuncs->pfnGetCaps = vboxWddmDispGetCaps;
-    pOpenData->pAdapterFuncs->pfnCreateDevice = vboxWddmDispCreateDevice;
-    pOpenData->pAdapterFuncs->pfnCloseAdapter = vboxWddmDispCloseAdapter;
-    pOpenData->DriverVersion = D3D_UMD_INTERFACE_VERSION;
-
-    vboxVDbgPrint(("<== "__FUNCTION__", pAdapter(0x%p)\n", pAdapter));
-
-    return S_OK;
+    vboxVDbgPrint(("<== "__FUNCTION__", FAILURE, hr (%d)\n", hr));
+
+    return hr;
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 29431)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 29432)
@@ -16,7 +16,7 @@
 #define ___VBoxDispD3D_h___
 
-#ifdef DEBUG
-# define VBOXWDDMDISP_DEBUG
-#endif
+#include "VBoxDispD3DIf.h"
+
+#include <iprt/cdefs.h>
 
 typedef struct VBOXWDDMDISP_ADAPTER
@@ -25,4 +25,6 @@
     UINT uIfVersion;
     UINT uRtVersion;
+    VBOXDISPD3D D3D;
+    IDirect3D9Ex * pD3D9If;
     D3DDDI_ADAPTERCALLBACKS RtCallbacks;
 } VBOXWDDMDISP_ADAPTER, *PVBOXWDDMDISP_ADAPTER;
@@ -40,20 +42,8 @@
 } VBOXWDDMDISP_DEVICE, *PVBOXWDDMDISP_DEVICE;
 
-#ifdef VBOXWDDMDISP_DEBUG
-VOID vboxVDbgDoPrint(LPCSTR szString, ...);
-
-#define vboxVDbgBreak() AssertBreakpoint()
-#define vboxVDbgPrint(_m) \
-    do { \
-        vboxVDbgDoPrint _m ; \
-    } while (0)
-#define vboxVDbgPrintR vboxVDbgPrint
-#define vboxVDbgPrintF vboxVDbgPrint
-#else
-#define vboxVDbgBreak() do {} while (0)
-#define vboxVDbgPrint(_m)  do {} while (0)
-#define vboxVDbgPrintR vboxVDbgPrint
-#define vboxVDbgPrintF vboxVDbgPrint
-#endif
+DECLINLINE(bool) vboxDispD3DIs3DEnabled(VBOXWDDMDISP_ADAPTER * pAdapter)
+{
+    return pAdapter->pD3D9If;
+}
 
 #endif /* #ifndef ___VBoxDispD3D_h___ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h	(revision 29432)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h	(revision 29432)
@@ -0,0 +1,39 @@
+/** @file
+ *
+ * VBoxVideo Display D3D User mode dll
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+#ifndef ___VBoxDispD3DCmn_h___
+#define ___VBoxDispD3DCmn_h___
+
+#ifdef DEBUG
+# define VBOXWDDMDISP_DEBUG
+#endif
+
+#ifdef VBOXWDDMDISP_DEBUG
+VOID vboxVDbgDoPrint(LPCSTR szString, ...);
+
+#define vboxVDbgBreak() AssertBreakpoint()
+#define vboxVDbgPrint(_m) \
+    do { \
+        vboxVDbgDoPrint _m ; \
+    } while (0)
+#define vboxVDbgPrintR vboxVDbgPrint
+#define vboxVDbgPrintF vboxVDbgPrint
+#else
+#define vboxVDbgBreak() do {} while (0)
+#define vboxVDbgPrint(_m)  do {} while (0)
+#define vboxVDbgPrintR vboxVDbgPrint
+#define vboxVDbgPrintF vboxVDbgPrint
+#endif
+
+#endif /* #ifndef ___VBoxDispD3DCmn_h___ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp	(revision 29432)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp	(revision 29432)
@@ -0,0 +1,52 @@
+/** @file
+ *
+ * VBoxVideo Display D3D User mode dll
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+#include "VBoxDispD3DIf.h"
+#include "VBoxDispD3DCmn.h"
+
+#include <iprt/assert.h>
+
+void VBoxDispD3DClose(VBOXDISPD3D *pD3D)
+{
+    FreeLibrary(pD3D->hD3DLib);
+    pD3D->hD3DLib = NULL;
+}
+
+
+HRESULT VBoxDispD3DOpen(VBOXDISPD3D *pD3D)
+{
+    pD3D->hD3DLib = LoadLibraryW(L"VBoxD3D9.dll");
+    Assert(pD3D->hD3DLib);
+    if (pD3D->hD3DLib)
+    {
+        pD3D->pfnDirect3DCreate9Ex = (PFNVBOXDISPD3DCREATE9EX)GetProcAddress(pD3D->hD3DLib, "Direct3DCreate9Ex");
+        Assert(pD3D->pfnDirect3DCreate9Ex);
+        if (pD3D->pfnDirect3DCreate9Ex)
+            return S_OK;
+        else
+        {
+            DWORD winErr = GetLastError();
+            vboxVDbgPrintR((__FUNCTION__": GetProcAddressW (for Direct3DCreate9Ex) failed, winErr = (%d)", winErr));
+        }
+
+        VBoxDispD3DClose(pD3D);
+    }
+    else
+    {
+        DWORD winErr = GetLastError();
+        vboxVDbgPrintR((__FUNCTION__": LoadLibraryW failed, winErr = (%d)", winErr));
+    }
+
+    return E_FAIL;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h	(revision 29432)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h	(revision 29432)
@@ -0,0 +1,37 @@
+/** @file
+ *
+ * VBoxVideo Display D3D User mode dll
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+#ifndef ___VBoxDispD3DIf_h___
+#define ___VBoxDispD3DIf_h___
+
+/* D3D headers */
+#include <D3D9.h>
+
+/* D3D functionality the VBOXDISPD3D provides */
+typedef HRESULT FNVBOXDISPD3DCREATE9EX(UINT SDKVersion, IDirect3D9Ex **ppD3D);
+typedef FNVBOXDISPD3DCREATE9EX *PFNVBOXDISPD3DCREATE9EX;
+
+typedef struct VBOXDISPD3D
+{
+    /* D3D functionality the VBOXDISPD3D provides */
+    PFNVBOXDISPD3DCREATE9EX pfnDirect3DCreate9Ex;
+
+    /* module handle */
+    HMODULE hD3DLib;
+} VBOXDISPD3D;
+
+HRESULT VBoxDispD3DOpen(VBOXDISPD3D *pD3D);
+void VBoxDispD3DClose(VBOXDISPD3D *pD3D);
+
+#endif /* ifndef ___VBoxDispD3DIf_h___ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp	(revision 29431)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp	(revision 29432)
@@ -266,5 +266,5 @@
     Assert (pRecord && (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL));
 
-    dfprintf((__FUNCTION__": VW %d\n", cb));
+//    dfprintf((__FUNCTION__": VW %d\n", cb));
 
     cbHwBufferAvail = vboxHwBufferAvail (pVBVA);
