Closed vlad2048 closed 8 months ago
I have updated the function as follows:
public static IntPtr GetWindowLongAuto(HWND hWnd, WindowLongFlags nIndex)
{
SetLastErrorEx(0, 0);
IntPtr ret = IntPtr.Size == 4 ? GetWindowLong(hWnd, nIndex) : GetWindowLongPtr(hWnd, nIndex);
if (ret == IntPtr.Zero)
Win32Error.GetLastError().ThrowIfFailed();
return ret;
}
Describe the bug and how to reproduce
0 is a valid return value for GetWindowLong & GetWindowLongPtr. So it cannot be used alone to detect an error.
For example querying the extended styles (WindowStylesEx) of a window can return 0 as a valid value.
What code is involved
Expected behavior Instead of just checking the return value against 0, we should:
Kernel32.SetLastError(0);
Kernel32.GetLastError
returns an error then throw the Win32ExceptionScreenshots n/a