Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetWindowPlacement fails with ERROR_INVALID_PARAMETER #394

Closed
rmcardle opened this issue Apr 30, 2023 · 0 comments
Closed

SetWindowPlacement fails with ERROR_INVALID_PARAMETER #394

rmcardle opened this issue Apr 30, 2023 · 0 comments

Comments

@rmcardle
Copy link

Describe the bug and how to reproduce

Tested on Windows 10 Pro 21H2 x64 using Vanara 3.4.14 from NuGet.

Vanara's WINDOWPLACEMENT structure includes the rcDevice field which is only defined in WinUser.h on Mac platforms, causing the size of the structure to be incorrect and SetWindowPlacement to fail.

From WinUser.h:

typedef struct tagWINDOWPLACEMENT {
    UINT  length;
    UINT  flags;
    UINT  showCmd;
    POINT ptMinPosition;
    POINT ptMaxPosition;
    RECT  rcNormalPosition;
#ifdef _MAC
    RECT  rcDevice;
#endif
} WINDOWPLACEMENT;

What code is involved

Initialize a Vanara.PInvoke.User32.WINDOWPLACEMENT structure with the length field set using (uint)Marshal.SizeOf(windowPlacement) (which returns 60) and use it in a call to Vanara.PInvoke.User32.SetWindowPlacement. The call returns false and GetLastError returns ERROR_INVALID_PARAMETER.

If you instead set length manually to 44 (the size of the WINDOWPLACEMENT structure without the rcDevice field), the call is successful and works as expected.

GetWindowPlacement returns a structure with the length set to 44.

Expected behavior

The call to SetWindowPlacement should succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants