Created
May 18, 2018 10:55
-
-
Save jonitis/c4d35dd3a7ce8cf47d1f4cd5bf665f01 to your computer and use it in GitHub Desktop.
DisplayMonitor::FromIdAsync() failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma comment(lib, "windowsapp") | |
#include <cstdio> | |
#include "winrt/base.h" | |
#include "winrt/Windows.Devices.Enumeration.h" | |
#include "winrt/Windows.Devices.Display.h" | |
using namespace std; | |
using namespace winrt; | |
using namespace Windows::Devices::Enumeration; | |
int main() | |
{ | |
init_apartment(); | |
using namespace Windows::Devices::Display; | |
const auto monitorSelector = DisplayMonitor::GetDeviceSelector(); | |
const auto devices = DeviceInformation::FindAllAsync(monitorSelector).get(); | |
for (const auto& device : devices) { | |
const auto id = device.Id(); | |
printf("id=%ls\n", id.c_str()); | |
DisplayMonitor monitor(nullptr); | |
try { | |
monitor = DisplayMonitor::FromIdAsync(id).get(); | |
} | |
catch (...) { | |
printf(" exception!\n"); | |
} | |
if (!monitor) | |
continue; | |
printf(" DisplayName = %ls\n", monitor.DisplayName().c_str()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BTW creating instance with DisplayMonitor::FromInterfaceIdAsync(interfaceId) works fine. But then you have to resort to win32 EnumDisplayDevices() function to obtain interfaceId.