Skip to content

Commit 0b12c51

Browse files
author
PinchToDebug
committed
Fixes crash on Windows 10
1 parent 5dd8cee commit 0b12c51

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

Pihole_Tray/MainWindow.xaml.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public partial class MainWindow : FluentWindow
3636
{
3737

3838

39-
39+
[SecurityCritical]
40+
[DllImport("dwmapi.dll", SetLastError = false, ExactSpelling = true)]
41+
public static extern int DwmSetWindowAttribute(IntPtr hwnd, uint dwAttribute, IntPtr pvAttribute, int cbAttribute);
4042

4143
[DllImport("user32.dll", SetLastError = true)]
4244
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
@@ -1469,33 +1471,27 @@ private async void ChangeBackground_Click(object sender, RoutedEventArgs e)
14691471

14701472

14711473

1472-
[SecurityCritical]
1473-
[DllImport("dwmapi.dll", SetLastError = false, ExactSpelling = true)]
1474-
public static extern int DwmSetWindowAttribute(IntPtr hwnd, uint dwAttribute, IntPtr pvAttribute, int cbAttribute);
14751474

14761475

14771476

14781477
private void fluentWindow_Loaded(object sender, RoutedEventArgs e)
14791478
{
1480-
var hwnd = new WindowInteropHelper(this).Handle;
1481-
var attribute = GCHandle.Alloc((uint)4, GCHandleType.Pinned);
1482-
var result = DwmSetWindowAttribute(hwnd, (uint)33, attribute.AddrOfPinnedObject(), sizeof(uint));
1483-
attribute.Free();
1484-
if (result != 0)
1479+
if (FileVersionInfo.GetVersionInfo("C:\\Windows\\System32\\kernel32.dll").FileBuildPart >= 22000) // Makes sure it doesn't change on Windows 10 as it crashes the program
14851480
{
1486-
throw Marshal.GetExceptionForHR(result);
1481+
var hwnd = new WindowInteropHelper(this).Handle;
1482+
var attribute = GCHandle.Alloc((uint)4, GCHandleType.Pinned);
1483+
var result = DwmSetWindowAttribute(hwnd, (uint)33, attribute.AddrOfPinnedObject(), sizeof(uint));
1484+
attribute.Free();
1485+
if (result != 0)
1486+
{
1487+
Debug.WriteLine("Couldn't change DWM");
1488+
}
14871489
}
1488-
14891490
}
14901491

14911492

14921493

14931494

1494-
1495-
1496-
1497-
1498-
14991495
private void SelectOtherInstnaceBTN_Click(object sender, RoutedEventArgs e)
15001496
{
15011497
OtherInstanceContextMenu.Items.Clear();

Pihole_Tray/Pihole_Tray.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<UseWPF>true</UseWPF>
99
<ApplicationIcon>Icon\Icon.ico</ApplicationIcon>
1010
<PackageIcon>icon.png</PackageIcon>
11-
<AssemblyVersion>0.1.2</AssemblyVersion>
12-
<FileVersion>0.1.2</FileVersion>
11+
<AssemblyVersion>0.1.3</AssemblyVersion>
12+
<FileVersion>0.1.3</FileVersion>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)