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

GetWindowLong/Ptr functions can fail, but don't return a Result #2773

Closed
qwerty01 opened this issue Jan 4, 2024 · 3 comments
Closed

GetWindowLong/Ptr functions can fail, but don't return a Result #2773

qwerty01 opened this issue Jan 4, 2024 · 3 comments
Labels
question Further information is requested

Comments

@qwerty01
Copy link

qwerty01 commented Jan 4, 2024

Suggestion

If we look at the docs for GetWindowLongPtrA (or any of the A/W Long/LongPtr variants), they all can fail by returning 0, however the generated bindings just return an isize: GetWindowLongPtrA.

The error handling might not be as simple as checking for 0 and returning a Result since a proper return type would be Result<Option<isize>>, where it returns Ok(None) when the function returns 0 without having an error (for example when SetWindowLong has not been called).

I've never actually seen it fail so I'm not entirely sure what the fail conditions vs succeed conditions on a 0 return look like (and the docs aren't very clear), but it would be nice to have the error helpers applied to these functions.

The returned value on the Ptr variants is also a pointer, but it's probably best to keep it as an isize since GetWindowLongPtrA and GetWindowLongPtrW return pseudo-values when the wrong A/W version is called.

@qwerty01 qwerty01 added the enhancement New feature or request label Jan 4, 2024
@riverar
Copy link
Collaborator

riverar commented Jan 4, 2024

A developer may also store/retrieve a 0 via DWL_USER, making this difficult to handle generically.

@kennykerr
Copy link
Collaborator

I think this is a case where the caller needs to figure things out since the way that errors are reported is very API specific and cannot be readily inferred through metadata.

@kennykerr kennykerr added question Further information is requested and removed enhancement New feature or request labels Jan 8, 2024
@kennykerr
Copy link
Collaborator

These APIs are already somewhat specialized and problematic (#1932) so I'd rather just leave this as is.

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

No branches or pull requests

3 participants