diff --git a/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs index 14b8ea6699..bc1ed00e05 100644 --- a/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs @@ -742,6 +742,9 @@ namespace Perspex.Win32.Interop [DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GlobalFree(IntPtr hMem); + [DllImport("kernel32.dll", SetLastError = true)] + public static extern IntPtr LoadLibrary(string fileName); + [DllImport("comdlg32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetSaveFileNameW")] public static extern bool GetSaveFileName(IntPtr lpofn); @@ -751,6 +754,8 @@ namespace Perspex.Win32.Interop [DllImport("comdlg32.dll")] public static extern int CommDlgExtendedError(); + public static bool ShCoreAvailable => LoadLibrary("shcore.dll") != IntPtr.Zero; + [DllImport("shcore.dll")] public static extern void SetProcessDpiAwareness(PROCESS_DPI_AWARENESS value); diff --git a/src/Windows/Perspex.Win32/Win32Platform.cs b/src/Windows/Perspex.Win32/Win32Platform.cs index f8e4f7d35d..5fb0a7c4b7 100644 --- a/src/Windows/Perspex.Win32/Win32Platform.cs +++ b/src/Windows/Perspex.Win32/Win32Platform.cs @@ -28,8 +28,11 @@ namespace Perspex.Win32 public Win32Platform() { - // Declare that this process is aware of per monitor DPI - UnmanagedMethods.SetProcessDpiAwareness(UnmanagedMethods.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE); + // Declare that this process is aware of per monitor DPI + if (UnmanagedMethods.ShCoreAvailable) + { + UnmanagedMethods.SetProcessDpiAwareness(UnmanagedMethods.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE); + } CreateMessageWindow(); } diff --git a/src/Windows/Perspex.Win32/WindowImpl.cs b/src/Windows/Perspex.Win32/WindowImpl.cs index 3b8fd6a802..6711663270 100644 --- a/src/Windows/Perspex.Win32/WindowImpl.cs +++ b/src/Windows/Perspex.Win32/WindowImpl.cs @@ -609,14 +609,17 @@ namespace Perspex.Win32 _hwnd, UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST); - uint dpix, dpiy; - if (UnmanagedMethods.GetDpiForMonitor( - monitor, - UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, - out dpix, - out dpiy) == 0) + if (UnmanagedMethods.ShCoreAvailable) { - _scaling = dpix / 96.0; + uint dpix, dpiy; + if (UnmanagedMethods.GetDpiForMonitor( + monitor, + UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, + out dpix, + out dpiy) == 0) + { + _scaling = dpix / 96.0; + } } }