Skip to content

Commit b2f5713

Browse files
committed
Fix crash on ×32 devices
1 parent 2026bb7 commit b2f5713

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

Flow.Launcher.Infrastructure/NativeMethods.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SystemParametersInfo
2222

2323
SetForegroundWindow
2424

25-
GetWindowLong
25+
WINDOW_LONG_PTR_INDEX
2626
GetForegroundWindow
2727
GetDesktopWindow
2828
GetShellWindow

Flow.Launcher.Infrastructure/PInvokeExtensions.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
namespace Windows.Win32;
66

7-
// Edited from: https://github.com/files-community/Files
87
internal static partial class PInvoke
98
{
9+
// SetWindowLong
10+
// Edited from: https://github.com/files-community/Files
11+
1012
[DllImport("User32", EntryPoint = "SetWindowLongW", ExactSpelling = true)]
11-
static extern int _SetWindowLong(HWND hWnd, int nIndex, int dwNewLong);
13+
private static extern int _SetWindowLong(HWND hWnd, int nIndex, int dwNewLong);
1214

1315
[DllImport("User32", EntryPoint = "SetWindowLongPtrW", ExactSpelling = true)]
14-
static extern nint _SetWindowLongPtr(HWND hWnd, int nIndex, nint dwNewLong);
16+
private static extern nint _SetWindowLongPtr(HWND hWnd, int nIndex, nint dwNewLong);
1517

1618
// NOTE:
1719
// CsWin32 doesn't generate SetWindowLong on other than x86 and vice versa.
@@ -22,4 +24,22 @@ public static unsafe nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nInd
2224
? _SetWindowLong(hWnd, (int)nIndex, (int)dwNewLong)
2325
: _SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong);
2426
}
27+
28+
// GetWindowLong
29+
30+
[DllImport("User32", EntryPoint = "GetWindowLongW", ExactSpelling = true)]
31+
private static extern int _GetWindowLong(HWND hWnd, int nIndex);
32+
33+
[DllImport("User32", EntryPoint = "GetWindowLongPtrW", ExactSpelling = true)]
34+
private static extern nint _GetWindowLongPtr(HWND hWnd, int nIndex);
35+
36+
// NOTE:
37+
// CsWin32 doesn't generate GetWindowLong on other than x86 and vice versa.
38+
// For more info, visit https://github.com/microsoft/CsWin32/issues/882
39+
public static unsafe nint GetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex)
40+
{
41+
return sizeof(nint) is 4
42+
? _GetWindowLong(hWnd, (int)nIndex)
43+
: _GetWindowLongPtr(hWnd, (int)nIndex);
44+
}
2545
}

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,17 @@ public static void DisableControlBox(Window window)
192192
SetWindowStyle(hwnd, WINDOW_LONG_PTR_INDEX.GWL_STYLE, style);
193193
}
194194

195-
private static int GetWindowStyle(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex)
195+
private static nint GetWindowStyle(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex)
196196
{
197-
var style = PInvoke.GetWindowLong(hWnd, nIndex);
197+
var style = PInvoke.GetWindowLongPtr(hWnd, nIndex);
198198
if (style == 0 && Marshal.GetLastPInvokeError() != 0)
199199
{
200200
throw new Win32Exception(Marshal.GetLastPInvokeError());
201201
}
202202
return style;
203203
}
204204

205-
private static nint SetWindowStyle(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, int dwNewLong)
205+
private static nint SetWindowStyle(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, nint dwNewLong)
206206
{
207207
PInvoke.SetLastError(WIN32_ERROR.NO_ERROR); // Clear any existing error
208208

0 commit comments

Comments
 (0)