Skip to content

Commit 3867a68

Browse files
TakooooootimschneebTim Schneebergerdanwalmsley
authored
Fix EntryPointNotFound on Windows 8 due to missing version check (#6471)
* Prevent calls to unavailable entrypoint 'GetDpiForMonitor' on Win8 (#5357) * Introduce Windows8 platform constant * wip Co-authored-by: Tim Schneeberger <[email protected]> Co-authored-by: Tim Schneeberger <[email protected]> Co-authored-by: Dan Walmsley <[email protected]>
1 parent f463529 commit 3867a68

File tree

7 files changed

+14
-9
lines changed

7 files changed

+14
-9
lines changed

src/Windows/Avalonia.Direct2D1/Avalonia.Direct2D1.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</ItemGroup>
1313
<ItemGroup>
1414
<ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" />
15+
<ProjectReference Include="..\Avalonia.Win32\Avalonia.Win32.csproj" />
1516
</ItemGroup>
1617
<Import Project="..\..\..\build\Rx.props" />
1718
<Import Project="..\..\..\build\SharpDX.props" />

src/Windows/Avalonia.Direct2D1/HwndRenderTarget.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Platform;
2+
using Avalonia.Win32;
23
using Avalonia.Win32.Interop;
34
using SharpDX;
45
using SharpDX.DXGI;
@@ -21,7 +22,7 @@ protected override SwapChain1 CreateSwapChain(Factory2 dxgiFactory, SwapChainDes
2122

2223
protected override Size2F GetWindowDpi()
2324
{
24-
if (UnmanagedMethods.ShCoreAvailable)
25+
if (UnmanagedMethods.ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8)
2526
{
2627
uint dpix, dpiy;
2728

src/Windows/Avalonia.Win32/FramebufferManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void DrawAndUnlock()
8787

8888
private Vector GetCurrentDpi()
8989
{
90-
if (UnmanagedMethods.ShCoreAvailable)
90+
if (UnmanagedMethods.ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8)
9191
{
9292
var monitor =
9393
UnmanagedMethods.MonitorFromWindow(_hwnd, UnmanagedMethods.MONITOR.MONITOR_DEFAULTTONEAREST);
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
using System;
2+
13
namespace Avalonia.Win32
24
{
3-
static class PlatformConstants
5+
public static class PlatformConstants
46
{
57
public const string WindowHandleType = "HWND";
68
public const string CursorHandleType = "HCURSOR";
9+
10+
public static readonly Version Windows8 = new Version(6, 2);
11+
public static readonly Version Windows7 = new Version(6, 1);
712
}
813
}

src/Windows/Avalonia.Win32/Win32GlManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Avalonia.OpenGL;
32
using Avalonia.OpenGL.Angle;
43
using Avalonia.OpenGL.Egl;
@@ -9,7 +8,6 @@ namespace Avalonia.Win32
98
{
109
static class Win32GlManager
1110
{
12-
private static readonly Version Windows7 = new Version(6, 1);
1311

1412
public static void Initialize()
1513
{
@@ -22,7 +20,7 @@ public static void Initialize()
2220
return wgl;
2321
}
2422

25-
if (opts?.AllowEglInitialization ?? Win32Platform.WindowsVersion > Windows7)
23+
if (opts?.AllowEglInitialization ?? Win32Platform.WindowsVersion > PlatformConstants.Windows7)
2624
{
2725
var egl = EglPlatformOpenGlInterface.TryCreate(() => new AngleWin32EglDisplay());
2826

src/Windows/Avalonia.Win32/Win32Platform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class Win32PlatformOptions
9494

9595
namespace Avalonia.Win32
9696
{
97-
class Win32Platform : IPlatformThreadingInterface, IPlatformSettings, IWindowingPlatform, IPlatformIconLoader, IPlatformLifetimeEventsImpl
97+
public class Win32Platform : IPlatformThreadingInterface, IPlatformSettings, IWindowingPlatform, IPlatformIconLoader, IPlatformLifetimeEventsImpl
9898
{
9999
private static readonly Win32Platform s_instance = new Win32Platform();
100100
private static Thread _uiThread;

src/Windows/Avalonia.Win32/WindowImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ private void CreateWindow()
764764
RegisterTouchWindow(_hwnd, 0);
765765
}
766766

767-
if (ShCoreAvailable)
768-
{
767+
if (ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8)
768+
{
769769
var monitor = MonitorFromWindow(
770770
_hwnd,
771771
MONITOR.MONITOR_DEFAULTTONEAREST);

0 commit comments

Comments
 (0)