Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Helper.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Helper.cpp	(revision 26178)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Helper.cpp	(revision 26179)
@@ -20,9 +20,12 @@
 // enable backdoor logging
 //#define LOG_ENABLED
-
+#ifndef VBOXWDDM
 extern "C"
 {
-#include <ntddk.h>
-}
+# include <ntddk.h>
+}
+#else
+# include "VBoxVideo.h"
+#endif
 
 #include <VBox/err.h>
@@ -30,4 +33,5 @@
 #include <VBox/VBoxGuestLib.h>
 
+#ifndef VBOXWDDM
 /* the video miniport headers not compatible with the NT DDK headers */
 typedef struct _VIDEO_POINTER_ATTRIBUTES
@@ -44,4 +48,5 @@
 #define VIDEO_MODE_COLOR_POINTER  0x04 // 1 if a color hardware pointer is
                                        // supported.
+#endif /* #ifndef VBOXWDDM */
 
 #include "Helper.h"
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk	(revision 26178)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk	(revision 26179)
@@ -93,4 +93,5 @@
  	VBoxVideoHGSMI.cpp \
  	VBoxVideo.cpp \
+    Helper.cpp \
  	wddm/VBoxVideoWddm.cpp \
 	wddm/VBoxVideoVidPn.cpp \
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 26178)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 26179)
@@ -149,4 +149,16 @@
 }
 
+VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal)
+{
+    return VideoPortGetRegistryParameters(Reg, pName, FALSE, VBoxRegistryCallback, pVal);
+}
+
+VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val)
+{
+    return VideoPortSetRegistryParameters(Reg, pName, &Val, sizeof(Val));
+}
+
+#endif /* #ifndef VBOXWDDM */
+
 /*
  * Global list of supported standard video modes. It will be
@@ -171,4 +183,7 @@
     /* custom video mode, otherwise Windows thinks there is no mode switch */
     static int gInvocationCounter = 0;
+
+    VBOXCMNREG Reg;
+    VBoxVideoCmnRegInit(DeviceExtension, &Reg);
 
     /* the resolution matrix */
@@ -558,27 +573,15 @@
         uint32_t xres, yres, bpp = 0;
         swprintf(keyname, L"CustomMode%dWidth", curKeyNo);
-        status = VideoPortGetRegistryParameters(DeviceExtension->pPrimary,
-                                                keyname,
-                                                FALSE,
-                                                VBoxRegistryCallback,
-                                                &xres);
+        status = VBoxVideoCmnRegQueryDword(Reg, keyname, &xres);
         /* upon the first error, we give up */
         if (status != NO_ERROR)
             break;
         swprintf(keyname, L"CustomMode%dHeight", curKeyNo);
-        status = VideoPortGetRegistryParameters(DeviceExtension->pPrimary,
-                                                keyname,
-                                                FALSE,
-                                                VBoxRegistryCallback,
-                                                &yres);
+        status = VBoxVideoCmnRegQueryDword(Reg, keyname, &yres);
         /* upon the first error, we give up */
         if (status != NO_ERROR)
             break;
         swprintf(keyname, L"CustomMode%dBPP", curKeyNo);
-        status = VideoPortGetRegistryParameters(DeviceExtension->pPrimary,
-                                                keyname,
-                                                FALSE,
-                                                VBoxRegistryCallback,
-                                                &bpp);
+        status = VBoxVideoCmnRegQueryDword(Reg, keyname, &bpp);
         /* upon the first error, we give up */
         if (status != NO_ERROR)
@@ -662,5 +665,4 @@
 
     } while(1);
-
 
     /*
@@ -811,14 +813,11 @@
 
                 /* store this video mode as the last custom video mode */
-                status = VideoPortSetRegistryParameters(DeviceExtension, L"CustomXRes",
-                                                        &xres, sizeof(ULONG));
+                status = VBoxVideoCmnRegSetDword(Reg, L"CustomXRes", xres);
                 if (status != NO_ERROR)
                     dprintf(("VBoxVideo: error %d writing CustomXRes\n", status));
-                status = VideoPortSetRegistryParameters(DeviceExtension, L"CustomYRes",
-                                                        &yres, sizeof(ULONG));
+                status = VBoxVideoCmnRegSetDword(Reg, L"CustomYRes", yres);
                 if (status != NO_ERROR)
                     dprintf(("VBoxVideo: error %d writing CustomYRes\n", status));
-                status = VideoPortSetRegistryParameters(DeviceExtension, L"CustomBPP",
-                                                        &bpp, sizeof(ULONG));
+                status = VBoxVideoCmnRegSetDword(Reg, L"CustomBPP", bpp);
                 if (status != NO_ERROR)
                     dprintf(("VBoxVideo: error %d writing CustomBPP\n", status));
@@ -860,7 +859,7 @@
     }
 #endif
-}
-
-#endif
+
+    VBoxVideoCmnRegFini(Reg);
+}
 
 /* Computes the size of a framebuffer. DualView has a few framebuffers of the computed size. */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 26178)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 26179)
@@ -113,4 +113,6 @@
 
 typedef PEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
+
+typedef struct _DEVICE_EXTENSION * VBOXCMNREG;
 #else
 #include <VBox/VBoxVideo.h>
@@ -120,4 +122,6 @@
 
 typedef KEVENT VBOXVCMNEVENT, *PVBOXVCMNEVENT;
+
+typedef HANDLE VBOXCMNREG;
 
 typedef enum
@@ -309,4 +313,6 @@
 
 #ifdef VBOXWDDM
+   PDEVICE_OBJECT pPDO;
+
    ULONG cSources;
    /* currently we define the array for the max possible size since we do not know
@@ -430,4 +436,20 @@
     pDeviceExtension->u.primary.VideoPortProcs.pfnFreePool(pDeviceExtension, Ptr);
 }
+
+DECLINLINE(VP_STATUS) VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg)
+{
+    *pReg = pDeviceExtension->pPrimary;
+    return NO_ERROR;
+}
+
+DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
+{
+    return NO_ERROR;
+}
+
+VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
+
+VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
+
 /* */
 
@@ -577,4 +599,19 @@
 }
 
+VP_STATUS VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg);
+
+DECLINLINE(VP_STATUS) VBoxVideoCmnRegFini(IN VBOXCMNREG Reg)
+{
+    if(!Reg)
+        return ERROR_INVALID_PARAMETER;
+
+    NTSTATUS Status = ZwClose(Reg);
+    return Status == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
+}
+
+VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal);
+
+VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val);
+
 /* */
 
@@ -612,4 +649,20 @@
     CONST DXGKARG_ENUMVIDPNCOFUNCMODALITY* pEnumCofuncModalityArg;
 }VBOXVIDPNCMCONTEXT, *PVBOXVIDPNCMCONTEXT;
+
+typedef struct VBOXVIDPN_NEW_SRCMODESET_CHECK
+{
+    VBOXVIDPNCMCONTEXT CommonInfo;
+    CONST D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
+    BOOLEAN bNeedAdjustment;
+}VBOXVIDPN_NEW_SRCMODESET_CHECK, *PVBOXVIDPN_NEW_SRCMODESET_CHECK;
+
+typedef struct VBOXVIDPN_NEW_SRCMODESET_POPULATION
+{
+    VBOXVIDPNCMCONTEXT CommonInfo;
+    CONST D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
+    /* new source mode (the one being populated) */
+    D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet;
+    CONST DXGK_VIDPNSOURCEMODESET_INTERFACE*  pNewVidPnSourceModeSetInterface;
+}VBOXVIDPN_NEW_SRCMODESET_POPULATION, *PVBOXVIDPN_NEW_SRCMODESET_POPULATION;
 
 /* !!!NOTE: The callback is responsible for releasing the path */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp	(revision 26178)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp	(revision 26179)
@@ -358,4 +358,19 @@
 }
 
+DECLCALLBACK(BOOLEAN) vboxVidPnCofuncModalitySourceModeCheck(PDEVICE_EXTENSION pDevExt, const D3DKMDT_HVIDPN hDesiredVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface,
+        D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet, const DXGK_VIDPNSOURCEMODESET_INTERFACE *pVidPnSourceModeSetInterface,
+        const D3DKMDT_VIDPN_SOURCE_MODE *pNewVidPnSourceModeInfo, PVOID pContext)
+{
+    NTSTATUS Status = STATUS_SUCCESS;
+    PVBOXVIDPN_NEW_SRCMODESET_CHECK pCbContext = (PVBOXVIDPN_NEW_SRCMODESET_CHECK)pContext;
+    pCbContext->CommonInfo.Status = STATUS_SUCCESS;
+
+    pVidPnSourceModeSetInterface->pfnReleaseModeInfo(hNewVidPnSourceModeSet, pNewVidPnSourceModeInfo);
+
+    pCbContext->CommonInfo.Status = Status;
+    return Status == STATUS_SUCCESS;
+
+}
+
 DECLCALLBACK(BOOLEAN) vboxVidPnCofuncModalitySourceModeEnum(PDEVICE_EXTENSION pDevExt, const D3DKMDT_HVIDPN hDesiredVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface,
         D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet, const DXGK_VIDPNSOURCEMODESET_INTERFACE *pVidPnSourceModeSetInterface,
@@ -394,47 +409,78 @@
     const DXGK_VIDPNSOURCEMODESET_INTERFACE *pVidPnSourceModeSetInterface;
     PVBOXVIDPNCMCONTEXT pCbContext = (PVBOXVIDPNCMCONTEXT)pContext;
+    NTSTATUS Status = STATUS_SUCCESS;
     pCbContext->Status = STATUS_SUCCESS;
-    NTSTATUS Status = pVidPnInterface->pfnAcquireSourceModeSet(hDesiredVidPn,
+
+    /* adjust scaling */
+    if (pCbContext->pEnumCofuncModalityArg->EnumPivotType != D3DKMDT_EPT_SCALING)
+    {
+        if (pNewVidPnPresentPathInfo->ContentTransformation.Scaling != D3DKMDT_VPPS_IDENTITY
+                && pNewVidPnPresentPathInfo->ContentTransformation.Scaling != D3DKMDT_VPPS_CENTERED
+                && pNewVidPnPresentPathInfo->ContentTransformation.Scaling != D3DKMDT_VPPS_STRETCHED)
+        {
+            const_cast<D3DKMDT_VIDPN_PRESENT_PATH*>(pNewVidPnPresentPathInfo)->ContentTransformation.Scaling = D3DKMDT_VPPS_IDENTITY;
+        }
+    }
+
+    /* adjust rotation */
+    if (pCbContext->pEnumCofuncModalityArg->EnumPivotType != D3DKMDT_EPT_ROTATION)
+    {
+        if (pNewVidPnPresentPathInfo->ContentTransformation.Rotation != D3DKMDT_VPPR_IDENTITY
+                && pNewVidPnPresentPathInfo->ContentTransformation.Rotation != D3DKMDT_VPPR_ROTATE90
+                && pNewVidPnPresentPathInfo->ContentTransformation.Rotation != D3DKMDT_VPPR_ROTATE180
+                && pNewVidPnPresentPathInfo->ContentTransformation.Rotation != D3DKMDT_VPPR_ROTATE270)
+        {
+            const_cast<D3DKMDT_VIDPN_PRESENT_PATH*>(pNewVidPnPresentPathInfo)->ContentTransformation.Rotation = D3DKMDT_VPPR_IDENTITY;
+        }
+    }
+
+    if (pCbContext->pEnumCofuncModalityArg->EnumPivotType != D3DKMDT_EPT_VIDPNSOURCE
+            || pNewVidPnPresentPathInfo->VidPnSourceId != pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnSourceId)
+    {
+
+        Status = pVidPnInterface->pfnAcquireSourceModeSet(hDesiredVidPn,
                     pNewVidPnPresentPathInfo->VidPnSourceId,
                     &hNewVidPnSourceModeSet,
                     &pVidPnSourceModeSetInterface);
-    Assert(Status == STATUS_SUCCESS);
-    if (Status == STATUS_SUCCESS)
-    {
-        CONST D3DKMDT_VIDPN_SOURCE_MODE* pPinnedVidPnSourceModeInfo;
-        Status = pVidPnSourceModeSetInterface->pfnAcquirePinnedModeInfo(hNewVidPnSourceModeSet, &pPinnedVidPnSourceModeInfo);
         Assert(Status == STATUS_SUCCESS);
         if (Status == STATUS_SUCCESS)
         {
-            if (pPinnedVidPnSourceModeInfo)
-            {
+            CONST D3DKMDT_VIDPN_SOURCE_MODE* pPinnedVidPnSourceModeInfo;
+            Status = pVidPnSourceModeSetInterface->pfnAcquirePinnedModeInfo(hNewVidPnSourceModeSet, &pPinnedVidPnSourceModeInfo);
+            Assert(Status == STATUS_SUCCESS);
+            if (Status == STATUS_SUCCESS)
+            {
+                if (!pPinnedVidPnSourceModeInfo)
+                {
+                    /* no pinned mode set, do adjustment */
+                    /* first iterate to see if there is anything that should be removed/added
+                     * if yes, create a new mode set and populate it with the necessary info */
+
+                    Status = vboxVidPnEnumSourceModes(pDevExt, hDesiredVidPn, pVidPnInterface,
+                        hNewVidPnSourceModeSet, pVidPnSourceModeSetInterface,
+                        vboxVidPnCofuncModalitySourceModeEnum, pCbContext);
+                    Assert(Status == STATUS_SUCCESS);
+                    if (Status == STATUS_SUCCESS)
+                    {
+                        Status = pCbContext->Status;
+                        Assert(Status == STATUS_SUCCESS);
+                        if (Status != STATUS_SUCCESS)
+                            drprintf((__FUNCTION__": vboxVidPnCofuncModalitySourceModeEnum failed Status(0x%x)\n", Status));
+                    }
+                    else
+                        drprintf((__FUNCTION__": vboxVidPnEnumSourceModes failed Status(0x%x)\n", Status));
+                }
+
                 /* nothing to be done here, just release */
                 pVidPnSourceModeSetInterface->pfnReleaseModeInfo(hNewVidPnSourceModeSet, pPinnedVidPnSourceModeInfo);
             }
             else
-            {
-                /* no pinned mode set, do adjustment */
-                Status = vboxVidPnEnumSourceModes(pDevExt, hDesiredVidPn, pVidPnInterface,
-                        hNewVidPnSourceModeSet, pVidPnSourceModeSetInterface,
-                        vboxVidPnCofuncModalitySourceModeEnum, pCbContext);
-                Assert(Status == STATUS_SUCCESS);
-                if (Status == STATUS_SUCCESS)
-                {
-                    Status = pCbContext->Status;
-                    Assert(Status == STATUS_SUCCESS);
-                    if (Status != STATUS_SUCCESS)
-                        drprintf((__FUNCTION__": vboxVidPnCofuncModalitySourceModeEnum failed Status(0x%x)\n", Status));
-                }
-                else
-                    drprintf((__FUNCTION__": vboxVidPnEnumSourceModes failed Status(0x%x)\n", Status));
-            }
+                drprintf((__FUNCTION__": pfnAcquirePinnedModeInfo failed Status(0x%x)\n", Status));
+
+            pVidPnInterface->pfnReleaseSourceModeSet(hDesiredVidPn, hNewVidPnSourceModeSet);
         }
         else
-            drprintf((__FUNCTION__": pfnAcquirePinnedModeInfo failed Status(0x%x)\n", Status));
-
-        pVidPnInterface->pfnReleaseSourceModeSet(hDesiredVidPn, hNewVidPnSourceModeSet);
-    }
-    else
-        drprintf((__FUNCTION__": pfnAcquireSourceModeSet failed Status(0x%x)\n", Status));
+            drprintf((__FUNCTION__": pfnAcquireSourceModeSet failed Status(0x%x)\n", Status));
+    }
 
     if (Status == STATUS_SUCCESS)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 26178)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 26179)
@@ -38,4 +38,131 @@
 {
     ExFreePool(pvMem);
+}
+
+#define VBOXWDDM_REG_DRVKEY_PREFIX L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class\\"
+
+NTSTATUS vboxWddmRegQueryDrvKeyName(PDEVICE_EXTENSION pDevExt, ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult)
+{
+    WCHAR fallBackBuf[2];
+    PWCHAR pSuffix;
+    bool bFallback = false;
+
+    if (cbBuf > sizeof(VBOXWDDM_REG_DRVKEY_PREFIX))
+    {
+        wcscpy(pBuf, VBOXWDDM_REG_DRVKEY_PREFIX);
+        pSuffix = pBuf + (sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2);
+        cbBuf -= sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2;
+    }
+    else
+    {
+        pSuffix = fallBackBuf;
+        cbBuf = sizeof (fallBackBuf);
+        bFallback = true;
+    }
+
+    NTSTATUS Status = IoGetDeviceProperty (pDevExt->pPDO,
+                                  DevicePropertyDriverKeyName,
+                                  cbBuf,
+                                  pSuffix,
+                                  &cbBuf);
+    if (Status == STATUS_SUCCESS && bFallback)
+        Status = STATUS_BUFFER_TOO_SMALL;
+    if (Status == STATUS_BUFFER_TOO_SMALL)
+        *pcbResult = cbBuf + sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2;
+
+    return Status;
+}
+
+NTSTATUS vboxWddmRegOpenKey(OUT PHANDLE phKey, IN PWCHAR pName, IN ACCESS_MASK fAccess)
+{
+    OBJECT_ATTRIBUTES ObjAttr;
+    UNICODE_STRING RtlStr;
+    RtlStr.Buffer = pName;
+    RtlStr.Length = USHORT(wcslen(pName) * sizeof(WCHAR));
+    RtlStr.MaximumLength = RtlStr.Length + sizeof(WCHAR);
+
+    InitializeObjectAttributes(&ObjAttr, &RtlStr, OBJ_CASE_INSENSITIVE, NULL, NULL);
+
+    return ZwOpenKey(phKey, fAccess, &ObjAttr);
+}
+
+NTSTATUS vboxWddmRegQueryValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT PDWORD pDword)
+{
+    UCHAR Buf[32]; /* should be enough */
+    ULONG cbBuf;
+    PKEY_VALUE_PARTIAL_INFORMATION pInfo = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
+    UNICODE_STRING RtlStr;
+    RtlStr.Buffer = pName;
+    RtlStr.Length = USHORT(wcslen(pName) * sizeof(WCHAR));
+    RtlStr.MaximumLength = RtlStr.Length + sizeof(WCHAR);
+    NTSTATUS Status = ZwQueryValueKey(hKey,
+                &RtlStr,
+                KeyValuePartialInformation,
+                pInfo,
+                sizeof(Buf),
+                &cbBuf);
+    if (Status == STATUS_SUCCESS)
+    {
+        if (pInfo->Type == REG_DWORD)
+        {
+            Assert(pInfo->DataLength == 4);
+            *pDword = *((PULONG)pInfo->Data);
+            return STATUS_SUCCESS;
+        }
+    }
+
+    return STATUS_INVALID_PARAMETER;
+}
+
+NTSTATUS vboxWddmRegSetValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT DWORD val)
+{
+    UCHAR Buf[32]; /* should be enough */
+    PKEY_VALUE_PARTIAL_INFORMATION pInfo = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
+    UNICODE_STRING RtlStr;
+    RtlStr.Buffer = pName;
+    RtlStr.Length = USHORT(wcslen(pName) * sizeof(WCHAR));
+    RtlStr.MaximumLength = RtlStr.Length + sizeof(WCHAR);
+    return ZwSetValueKey(hKey, &RtlStr,
+            NULL, /* IN ULONG  TitleIndex  OPTIONAL, reserved */
+            REG_DWORD,
+            &val,
+            sizeof(val));
+}
+
+VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal)
+{
+    if(!Reg)
+        return ERROR_INVALID_PARAMETER;
+    NTSTATUS Status = vboxWddmRegQueryValueDword(Reg, pName, (PDWORD)pVal);
+    return Status == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
+}
+
+VP_STATUS VBoxVideoCmnRegSetDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t Val)
+{
+    if(!Reg)
+        return ERROR_INVALID_PARAMETER;
+    NTSTATUS Status = vboxWddmRegSetValueDword(Reg, pName, Val);
+    return Status == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
+}
+
+VP_STATUS VBoxVideoCmnRegInit(IN PDEVICE_EXTENSION pDeviceExtension, OUT VBOXCMNREG *pReg)
+{
+    WCHAR Buf[512];
+    ULONG cbBuf = sizeof(Buf);
+    NTSTATUS Status = vboxWddmRegQueryDrvKeyName(pDeviceExtension, cbBuf, Buf, &cbBuf);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        Status = vboxWddmRegOpenKey(pReg, Buf, GENERIC_READ | GENERIC_WRITE);
+        Assert(Status == STATUS_SUCCESS);
+        if(Status == STATUS_SUCCESS)
+            return NO_ERROR;
+    }
+
+    /* fall-back to make the subsequent VBoxVideoCmnRegXxx calls treat the fail accordingly
+     * basically needed to make as less modifications to the current XPDM code as possible */
+    *pReg = NULL;
+
+    return ERROR_INVALID_PARAMETER;
 }
 
@@ -174,4 +301,5 @@
     if (pContext)
     {
+        pContext->pPDO = PhysicalDeviceObject;
         *MiniportDeviceContext = pContext;
     }
