Fixing an overflow exception.

This commit is contained in:
Robin Krom 2022-02-18 23:18:26 +01:00
commit fb965c2887
No known key found for this signature in database
GPG key ID: BCC01364F1371490
3 changed files with 9 additions and 9 deletions

View file

@ -782,7 +782,9 @@ namespace Greenshot.Base.Core
/// </summary> /// </summary>
public WindowStyleFlags WindowStyle public WindowStyleFlags WindowStyle
{ {
get => (WindowStyleFlags) User32.GetWindowLongWrapper(Handle, (int) WindowLongIndex.GWL_STYLE); get => unchecked(
(WindowStyleFlags)User32.GetWindowLongWrapper(Handle, (int)WindowLongIndex.GWL_STYLE).ToInt64()
);
set => User32.SetWindowLongWrapper(Handle, (int) WindowLongIndex.GWL_STYLE, new IntPtr((long) value)); set => User32.SetWindowLongWrapper(Handle, (int) WindowLongIndex.GWL_STYLE, new IntPtr((long) value));
} }

View file

@ -32,7 +32,7 @@ namespace Greenshot.Base.UnmanagedHelpers.Enums
public enum WindowStyleFlags : int public enum WindowStyleFlags : int
{ {
//WS_OVERLAPPED = 0x00000000, //WS_OVERLAPPED = 0x00000000,
WS_POPUP = -2147483648, WS_POPUP = -2147483648, // 0x80000000
WS_CHILD = 0x40000000, WS_CHILD = 0x40000000,
WS_MINIMIZE = 0x20000000, WS_MINIMIZE = 0x20000000,
WS_VISIBLE = 0x10000000, WS_VISIBLE = 0x10000000,

View file

@ -127,7 +127,7 @@ namespace Greenshot.Base.UnmanagedHelpers
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, IntPtr lParam); public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32", SetLastError = true, EntryPoint = "GetWindowLong")] [DllImport("user32", SetLastError = true, EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr hWnd, int index); public static extern IntPtr GetWindowLong(IntPtr hWnd, int index);
[DllImport("user32", SetLastError = true, EntryPoint = "GetWindowLongPtr")] [DllImport("user32", SetLastError = true, EntryPoint = "GetWindowLongPtr")]
public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
@ -276,16 +276,14 @@ namespace Greenshot.Base.UnmanagedHelpers
/// <param name="hWnd"></param> /// <param name="hWnd"></param>
/// <param name="nIndex"></param> /// <param name="nIndex"></param>
/// <returns></returns> /// <returns></returns>
public static long GetWindowLongWrapper(IntPtr hWnd, int nIndex) public static IntPtr GetWindowLongWrapper(IntPtr hWnd, int nIndex)
{ {
if (IntPtr.Size == 8) if (IntPtr.Size == 8)
{ {
return GetWindowLongPtr(hWnd, nIndex).ToInt64(); return GetWindowLongPtr(hWnd, nIndex);
}
else
{
return GetWindowLong(hWnd, nIndex);
} }
return GetWindowLong(hWnd, nIndex);
} }
/// <summary> /// <summary>