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

Feature request: Provide bitness-independent mappings where available #1493

Closed
tim-weis opened this issue Feb 3, 2022 · 2 comments · Fixed by #1932
Closed

Feature request: Provide bitness-independent mappings where available #1493

tim-weis opened this issue Feb 3, 2022 · 2 comments · Fixed by #1932
Labels
enhancement New feature or request

Comments

@tim-weis
Copy link
Contributor

tim-weis commented Feb 3, 2022

Motivation

64-bit Windows introduced a number of new APIs to accommodate for increased pointer type widths. A prominent example being the [Get|Set]WindowLongPtr[A|W] family of functions. They supersede the [Get|Set]WindowLong[A|W] functions, but aren't available on 32-bit Windows.

As a consequence, code that needs to be compatible with 32-bit Windows as well as 64-bit Windows must conditionally pull in the required dependencies. C and C++ developers using the Windows SDK have this solved: They can unanimously use the *-Ptr-variants and rely on the preprocessor to transform their code as needed.

Rust developers using the windows or windows-sys crates, on the other hand, will not find themselves in as comfortable a situation. Getting code to compile across architectures with differing pointer widths usually involves a fair amount of conditional code (see the Direct2D sample for an example).

Ideally, clients should be able to just call GetWindowLongPtrA and have their code compile across architectures.

Drawbacks

I'm not aware of any adverse effects in providing this.

Rationale and alternatives

Rationale

The developer experience for clients of windows and windows-sys should be on par with that of C and C++ developers using the Windows SDK. This feature request addresses an issue where this is not the case.

Alternatives

The alternative is propagating the responsibility for writing bitness-adaptive code to clients or crate authors.

Additional context

Prior art

The winapi crate solves this by re-exporting the *-Ptr-variants as aliases for 32-bit platforms, e.g.

#[cfg(target_pointer_width = "32")]
pub use self::GetWindowLongA as GetWindowLongPtrA;

Unresolved questions

  • Are there other API calls that fit this category?
  • Should a solution be metadata-driven or would a hand-crafted implementation (akin to what winapi does) be manageable enough?
@tim-weis tim-weis added the enhancement New feature or request label Feb 3, 2022
@kennykerr
Copy link
Collaborator

Thanks Tim. I don't think there will be any metadata to link them together, but I would like to simplify this if possible.

@kennykerr
Copy link
Collaborator

Sorry for the delay - let me know what you think of #1932.

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

Successfully merging a pull request may close this issue.

2 participants