I want to use wddm driver+winrt to realize headset driver, in WDDM driver I change the VSDB in edid to the value needed by the headset and report it to the system, then in winrt project by calling GetCurrentTargets() I've successfully get the above monito

Mark Qian 钱小兵 0 Reputation points
2025-07-01T03:32:35.85+00:00
auto manager = winrt::DisplayManager::Create(winrt::DisplayManagerOptions::EnforceSourceOwnership);

bool shouldRetry;

do

{

    shouldRetry = false;

    winrt::IVectorView<winrt::DisplayTarget> targets = manager.GetCurrentTargets();

    auto myTargets = winrt::single_threaded_vector<winrt::DisplayTarget>();

    for (auto&& target : targets)

    {

        if (target.UsageKind() == winrt::DisplayMonitorUsageKind::HeadMounted)

        {

            // You can look at a DisplayMonitor to inspect the EDID of the device

            winrt::DisplayMonitor monitor = target.TryGetMonitor();

            winrt::com_array<uint8_t> edidBuffer = monitor.GetDescriptor(winrt::DisplayMonitorDescriptorKind::Edid);

            if (IsMyEdid(edidBuffer))

            {

                auto stateResult = manager.TryAcquireTarget(target);

                myTargets.Append(target);

                winrt::DisplayAdapter adapter = target.Adapter();

                std::wcout << L"Found a matching HMD: " << monitor.DisplayName().c_str() << std::endl;

                std::wcout << L"Found a matching HMD, deviceid: " << monitor.DeviceId()<< std::endl;

            }

        }

    }

    if (myTargets.Size() == 0)

    {

        std::wcout << L"Failed to find an HMD" << std::endl;

        return -1;

    }

    // Create a state object for setting modes on the targets


   

    auto stateResult = manager.TryAcquireTargetsAndCreateEmptyState(myTargets);

    if (stateResult.ExtendedErrorCode() != 0)

    {

        shouldRetry = true;

        check_hresult(stateResult.ExtendedErrorCode());

        continue;

    }

    else

        shouldRetry = false;
```。。。

}while(shouldretry)

Windows development | Windows Driver Kit (WDK)
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.