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

implement GetWindowPlacement #67

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Conversation

LinusU
Copy link
Contributor

@LinusU LinusU commented Sep 22, 2024

Opening this to get some discussion around how to implement variable length structs 🤔

According to MSDN:

[...] Before calling GetWindowPlacement, set the length member to sizeof(WINDOWPLACEMENT). GetWindowPlacement fails if lpwndpl->length is not set correctly.

ref

The problem is that my program (Pocoman) doesn't seem to initialize the length property at all. From looking at Ghidra I think that the variable simply isn't initialized at all, so it has the value of whatever happened to be in that stack position previously. (note that I don't have much experience with this so I could absolutely be wrong)

Here is what dbg!(&wndpl); prints:

&wndpl = WINDOWPLACEMENT {
    length: 50078,
    flags: 4265673,
    showCmd: 4379564,
    ptMinPosition: POINT {
        x: 4260799,
        y: 4,
    },
    ptMaxPosition: POINT {
        x: 4,
        y: 4,
    },
    rcNormalPosition: RECT {
        left: 0,
        top: 50078,
        right: 4247973,
        bottom: 1183232,
    },
    rcDevice: RECT {
        left: 63,
        top: 5,
        right: 16,
        bottom: 4194304,
    },
}

I'm not really sure what to do here. I'm guessing that the input characteristics of length was introduced in a later version, in order to add rcDevice in a backwards compatible way. But I don't understand how that could be since presumable it has been called with uninitialized data for length before that 🤔

LinusU referenced this pull request in LinusU/retrowin32 Sep 22, 2024
win32/src/winapi/user32/window.rs Outdated Show resolved Hide resolved
win32/src/winapi/user32/window.rs Outdated Show resolved Hide resolved
@evmar
Copy link
Owner

evmar commented Sep 23, 2024

I think for now it's fine to just assume it's the size we expect, it looks like wine does this anyway. But I'd fill in length anyway just to be sure.

@LinusU LinusU changed the title wip: implement GetWindowPlacement implement GetWindowPlacement Oct 7, 2024
@LinusU
Copy link
Contributor Author

LinusU commented Oct 7, 2024

@evmar Updated 👍

it seems like the larger size (rcDevice field) is only for old (pre-intel) Mac 😅

@evmar evmar merged commit 5e634d9 into evmar:main Oct 7, 2024
3 checks passed
@LinusU LinusU deleted the GetWindowPlacement branch October 8, 2024 08:03
@LinusU LinusU mentioned this pull request Oct 8, 2024
27 tasks
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

Successfully merging this pull request may close these issues.

2 participants