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

SetWindowLongPtrW documentation expects isize, compilation fails expecting i32 (i686-pc-windows-msvc) #3304

Closed
LGUG2Z opened this issue Sep 30, 2024 · 1 comment
Labels
question Further information is requested

Comments

@LGUG2Z
Copy link

LGUG2Z commented Sep 30, 2024

Summary

The docs state that SetWindowLongPtrW's final argument should take an isize: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/UI/WindowsAndMessaging/fn.SetWindowLongPtrW.html

When compiling against stable-i686-pc-windows-msvc, a compilation error suggests that an i32 is expected:

cargo +stable-i686-pc-windows-msvc build
error[E0308]: mismatched types
    --> src/main.rs:8:72
     |
8    |         SetWindowLongPtrW(HWND::default(), WINDOW_LONG_PTR_INDEX(-20), 1_isize);
     |         ----------------- arguments to this function are incorrect     ^^^^^^^ expected `i32`, found `isize`
     |
note: function defined here
    --> C:\Users\LGUG2Z\.cargo\registry\src\index.crates.io-1cd66030c949c28d\windows-0.58.0\src\Windows\Win32\UI\WindowsAndMessaging\mod.rs:3034:15
     |
3034 | pub unsafe fn SetWindowLongW<P0>(hwnd: P0, nindex: WINDOW_LONG_PTR_INDEX, dwnewlong: i32) -> i32
     |               ^^^^^^^^^^^^^^
help: change the type of the numeric literal from `isize` to `i32`
     |
8    |         SetWindowLongPtrW(HWND::default(), WINDOW_LONG_PTR_INDEX(-20), 1_i32);
     |                                                                          ~~~

For more information about this error, try `rustc --explain E0308`.
error: could not compile `winrs-repro` (bin "winrs-repro") due to 1 previous error

Compilation against stable-x86_64-pc-windows-msvc succeeds as expected.

Crate manifest

[package]
name = "winrs-repro"
version = "0.1.0"
edition = "2021"

[dependencies]

[dependencies.windows]
version = "0.58"
features = [
    "Win32_Foundation",
    "Win32_UI_WindowsAndMessaging",
]

Crate code

use windows::Win32::{
    Foundation::HWND,
    UI::WindowsAndMessaging::{SetWindowLongPtrW, WINDOW_LONG_PTR_INDEX},
};

fn main() {
    unsafe {
        SetWindowLongPtrW(HWND::default(), WINDOW_LONG_PTR_INDEX(-20), 1_isize);
    }
}
@LGUG2Z LGUG2Z added the bug Something isn't working label Sep 30, 2024
@kennykerr kennykerr added question Further information is requested and removed bug Something isn't working labels Sep 30, 2024
@kennykerr
Copy link
Collaborator

That's because SetWindowLongPtrW does not actually exist on 32-bit builds of Windows, but as a convenience it is defined in terms of SetWindowLongW to make it easier to target both 32-bit and 64-bit builds.

#[cfg(target_pointer_width = "32")]
pub use GetWindowLongA as GetWindowLongPtrA;
#[cfg(target_pointer_width = "32")]
pub use GetWindowLongW as GetWindowLongPtrW;
#[cfg(target_pointer_width = "32")]
pub use SetWindowLongA as SetWindowLongPtrA;
#[cfg(target_pointer_width = "32")]
pub use SetWindowLongW as SetWindowLongPtrW;

LGUG2Z added a commit to LGUG2Z/komorebi that referenced this issue Oct 1, 2024
This commit ensures that komorebi will compile when targeting 32-bit
architectures, namely `stable-i686-pc-windows-msvc`.

Thanks to @kennykerr for pointing out that Get/SetWindowLongPtrA/W calls
don't actually exist on 32-bit builds of Windows and are aliased instead
to Get/SetWindowLongA/W which take i32 args instead of isize args:
microsoft/windows-rs#3304
@LGUG2Z LGUG2Z closed this as completed Oct 1, 2024
LGUG2Z added a commit to LGUG2Z/komorebi that referenced this issue Oct 1, 2024
This commit ensures that komorebi will compile when targeting 32-bit
architectures, namely `stable-i686-pc-windows-msvc`.

Thanks to @kennykerr for pointing out that Get/SetWindowLongPtrA/W calls
don't actually exist on 32-bit builds of Windows and are aliased instead
to Get/SetWindowLongA/W which take i32 args instead of isize args:
microsoft/windows-rs#3304
LGUG2Z added a commit to LGUG2Z/komorebi that referenced this issue Oct 2, 2024
This commit ensures that komorebi will compile when targeting 32-bit
architectures, namely `stable-i686-pc-windows-msvc`.

Thanks to @kennykerr for pointing out that Get/SetWindowLongPtrA/W calls
don't actually exist on 32-bit builds of Windows and are aliased instead
to Get/SetWindowLongA/W which take i32 args instead of isize args:
microsoft/windows-rs#3304
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

2 participants