Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 106685)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 106686)
@@ -1948,6 +1948,8 @@
                  * Try to find the source mode.
                  */
-                DISPLAYCONFIG_MODE_INFO *pSrcModeInfo = NULL;
-                int iSrcModeInfo = -1;
+                DISPLAYCONFIG_MODE_INFO *pSrcModeInfo = NULL, *pTgtModeInfo = NULL;
+                int iSrcModeInfo = -1, iTgtModeInfo = -1;
+                int cModeInfoNew = 0;
+
                 for (UINT j = 0; j < DispCfg.cModeInfoArray; ++j)
                 {
@@ -1961,10 +1963,27 @@
                 }
 
+                for (UINT j = 0; j < DispCfg.cModeInfoArray; ++j)
+                {
+                    if (   DispCfg.pModeInfoArray[j].infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET
+                        && DispCfg.pModeInfoArray[j].id == pDispDef->idDisplay)
+                    {
+                        pTgtModeInfo = &DispCfg.pModeInfoArray[j];
+                        iTgtModeInfo = (int)j;
+                        break;
+                    }
+                }
+
                 if (pSrcModeInfo == NULL)
+                    cModeInfoNew++;
+
+                if (pTgtModeInfo == NULL)
+                    cModeInfoNew++;
+
+                if (cModeInfoNew > 0)
                 {
-                    /* No mode yet. Add the new mode to the ModeInfo array. */
                     DISPLAYCONFIG_MODE_INFO *paModeInfo = (DISPLAYCONFIG_MODE_INFO *)RTMemRealloc(DispCfg.pModeInfoArray,
-                                                                                                    (DispCfg.cModeInfoArray + 1)
+                                                                                                    (DispCfg.cModeInfoArray + cModeInfoNew)
                                                                                                   * sizeof(paModeInfo[0]));
+
                     if (!paModeInfo)
                     {
@@ -1974,13 +1993,36 @@
 
                     DispCfg.pModeInfoArray = paModeInfo;
-                    DispCfg.cModeInfoArray += 1;
-
-                    iSrcModeInfo = DispCfg.cModeInfoArray - 1;
-                    pSrcModeInfo = &DispCfg.pModeInfoArray[iSrcModeInfo];
-                    RT_ZERO(*pSrcModeInfo);
-
-                    pSrcModeInfo->infoType  = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE;
-                    pSrcModeInfo->id        = pDispDef->idDisplay;
-                    pSrcModeInfo->adapterId = DispCfg.pModeInfoArray[0].adapterId;
+
+                    if (pSrcModeInfo == NULL)
+                    {
+                        iSrcModeInfo = DispCfg.cModeInfoArray;
+                        pSrcModeInfo = &paModeInfo[iSrcModeInfo];
+                        DispCfg.cModeInfoArray++;
+
+                        RT_ZERO(*pSrcModeInfo);
+                        pSrcModeInfo->infoType  = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE;
+                        pSrcModeInfo->id        = pDispDef->idDisplay;
+                        pSrcModeInfo->adapterId = DispCfg.pModeInfoArray[0].adapterId;
+                    }
+
+                    if (pTgtModeInfo == NULL)
+                    {
+                        iTgtModeInfo = DispCfg.cModeInfoArray;
+                        pTgtModeInfo = &paModeInfo[iTgtModeInfo];
+                        DispCfg.cModeInfoArray++;
+
+                        RT_ZERO(*pTgtModeInfo);
+                        pTgtModeInfo->infoType  = DISPLAYCONFIG_MODE_INFO_TYPE_TARGET;
+                        pTgtModeInfo->id        = pDispDef->idDisplay;
+                        pTgtModeInfo->adapterId = DispCfg.pModeInfoArray[0].adapterId;
+
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.pixelRate = 0xfffffffe;
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.hSyncFreq.Numerator = 0xfffffffe;
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.hSyncFreq.Denominator = 0xfffffffe;
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.vSyncFreq.Numerator = 0xfffffffe;
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.vSyncFreq.Denominator = 0xfffffffe;
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.videoStandard = 255;
+                        pTgtModeInfo->targetMode.targetVideoSignalInfo.scanLineOrdering = DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE;
+                    }
                 }
 
@@ -1989,4 +2031,6 @@
                 {
                     pSrcModeInfo->sourceMode.width = pDispDef->cx;
+                    pTgtModeInfo->targetMode.targetVideoSignalInfo.activeSize.cx =
+                    pTgtModeInfo->targetMode.targetVideoSignalInfo.totalSize.cx = pDispDef->cx;
                 }
 
@@ -1994,4 +2038,6 @@
                 {
                     pSrcModeInfo->sourceMode.height = pDispDef->cy;
+                    pTgtModeInfo->targetMode.targetVideoSignalInfo.activeSize.cy =
+                    pTgtModeInfo->targetMode.targetVideoSignalInfo.totalSize.cy = pDispDef->cy;
                 }
 
@@ -2030,9 +2076,5 @@
 
                 Assert(pPathInfo->targetInfo.id == pDispDef->idDisplay);
-                /* "If the index value is DISPLAYCONFIG_PATH_MODE_IDX_INVALID ..., this indicates
-                 * the mode information is not being specified. It is valid for the path plus source mode ...
-                 * information to be specified for a given path."
-                 */
-                pPathInfo->targetInfo.modeInfoIdx      = DISPLAYCONFIG_PATH_MODE_IDX_INVALID;
+                pPathInfo->targetInfo.modeInfoIdx      = iTgtModeInfo;
                 pPathInfo->targetInfo.outputTechnology = DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15;
                 pPathInfo->targetInfo.rotation         = DISPLAYCONFIG_ROTATION_IDENTITY;
@@ -2070,4 +2112,9 @@
         vboxDispIfWddmDcLogRel(&DispCfg, fSetFlags);
         fSetFlags |= SDC_ALLOW_CHANGES;
+    }
+    else
+    {
+        WARN(("VBoxTray:(WDDM) pfnSetDisplayConfig Ok to VALIDATE winEr %d.\n", winEr));
+        vboxDispIfWddmDcLogRel(&DispCfg, fSetFlags);
     }
 
