Skip to content

Commit 6f36be5

Browse files
authored
SetThreadDpiAwareness for host error dialog (#81930)
1 parent b4c1a09 commit 6f36be5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/native/corehost/apphost/apphost.windows.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ namespace
323323

324324
trace::verbose(_X("Showing error dialog for application: '%s' - error code: 0x%x - url: '%s' - details: %s"), executable_name, error_code, url.c_str(), details.c_str());
325325

326+
HMODULE user32 = ::LoadLibraryExW(L"user32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
327+
if (user32 != nullptr)
328+
{
329+
using set_thread_dpi = DPI_AWARENESS_CONTEXT(WINAPI*)(DPI_AWARENESS_CONTEXT context);
330+
set_thread_dpi set_thread_dpi_func = (set_thread_dpi)::GetProcAddress(user32, "SetThreadDpiAwarenessContext");
331+
332+
// Since this is only for errors shown when the process is about to exit, we
333+
// skip resetting to the previous context to minimize impact on apphost size
334+
if (set_thread_dpi_func != nullptr)
335+
(void) set_thread_dpi_func(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
336+
337+
::FreeLibrary(user32);
338+
}
339+
326340
if (enable_visual_styles())
327341
{
328342
// Task dialog requires enabling visual styles

0 commit comments

Comments
 (0)