Programmatically - Cross-adapter Clone with NVIDIA and Intel

Nouman 1 Reputation point
2022-04-27T05:27:57.497+00:00

I have been using this script to optionally clone/duplicate and two displays, but this fails when doing cross adaptor cloning, for example "cloning main display (Intel adapter) to external display (Nvidia adapter)"

  1. include <iostream>
  2. include <windows.h>
  3. include <vector>
    1. int main()
  4. {
  5. UINT32 pathSize;
  6. UINT32 modeSize;
  7. GetDisplayConfigBufferSizes(QDC_ALL_PATHS, &pathSize, &modeSize);
    1. std::vector<DISPLAYCONFIG_PATH_INFO> pathArray(pathSize);
  8. std::vector<DISPLAYCONFIG_MODE_INFO> modeArray(modeSize);
  9. QueryDisplayConfig(QDC_ALL_PATHS, &pathSize, &pathArray[0], &modeSize, &modeArray[0], NULL);
  10. pathArray[1].sourceInfo.id = pathArray[0].sourceInfo.id;
  11. pathArray[1].sourceInfo.modeInfoIdx = pathArray[0].sourceInfo.modeInfoIdx;
  12. UINT8 flags = SDC_APPLY | SDC_SAVE_TO_DATABASE | SDC_ALLOW_CHANGES | SDC_USE_SUPPLIED_DISPLAY_CONFIG;
  13. SetDisplayConfig(static_cast<UINT32>(pathArray.size()), &pathArray[0], static_cast<UINT32>(modeArray.size()), &modeArray[0], flags);
  14. return 0;
  15. }

when I use :
SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_CLONE | SDC_APPLY);

that works, but this calls the last configuration in the database but does not allow me to select displays optionally.

could you please help me with that.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
749 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,511 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,574 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,902 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,226 Reputation points Microsoft Vendor
    2022-04-27T08:20:34.743+00:00

    According to CCD example pseudocode and part of the answer, you need to find out the path from the current primary(adapterId A) to targets(adapterId B). To find out the path, the previous mentioned answer tries to enable each source+target pair that contains the target(adapterId B) until one works.
    Relationship of Mode Information to Path Information has a picture for explanation.
    196838-image.png
    Finally, It‘s important to check whether all your monitors(adapterId A &B) are available in the Display setting or not.

    0 comments No comments

  2. Limitless Technology 39,506 Reputation points
    2022-05-03T07:19:35.623+00:00

    Hi there,

    The issue could be related to Display drivers which are not allowing you to select displays optionally. Also try to enable clone mode and see if that changes the way the script functions., follow these steps to enable the clone mode.

    1. In desktop mode, right-click on the Desktop and select Graphics Properties.
    2. Click Display > Multiple Displays.
      Under Select Display Mode, click Clone Displays; for old CUI, click the drop-down arrow for Operating Mode and select Clone Display.

    Hope this resolves your Query!!


    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments