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

Cursor related const's are only compatible with LoadCursorW #1748

Open
mdeforge opened this issue Dec 1, 2023 · 5 comments
Open

Cursor related const's are only compatible with LoadCursorW #1748

mdeforge opened this issue Dec 1, 2023 · 5 comments
Labels
broken api An API is inaccurate and could lead to runtime failure rust Critical for Rust adoption

Comments

@mdeforge
Copy link

mdeforge commented Dec 1, 2023

Summary

Cursor related const's such as IDC_ARROW in Windows\Win32\UI\WindowsAndMessaging\mod.rs are only compatible with the wide LoadCursorW function and not with the non-wide LoadCursorA function.

This is due to the const's being declared as PCWSTR's and not PCSTR's. However, switching would break the wide version of the function.

I'm new to Rust, so I may be missing an easy solution here. However, I think this use case should be supported, no?

Error:

error[E0277]: the trait bound `PCWSTR: CanInto<PCSTR>` is not satisfied
    --> src\main.rs:5:49
     |
5    |         let version = LoadCursorA(HINSTANCE(0), IDC_ARROW);
     |                       -----------               ^^^^^^^^^ the trait `CanInto<PCSTR>` is not implemented for `PCWSTR`
     |                       |
     |                       required by a bound introduced by this call
     |
     = help: the following other types implement trait `CanInto<T>`:
               <IAgileObject as CanInto<IUnknown>>
               <IAgileReference as CanInto<IUnknown>>
               <IErrorInfo as CanInto<IUnknown>>
               <ILanguageExceptionErrorInfo as CanInto<IUnknown>>
               <ILanguageExceptionErrorInfo2 as CanInto<IUnknown>>
               <ILanguageExceptionErrorInfo2 as CanInto<ILanguageExceptionErrorInfo>>
               <IPropertyValue as CanInto<IUnknown>>
               <IPropertyValue as CanInto<IInspectable>>
             and 12 others
     = note: required for `PCWSTR` to implement `IntoParam<PCSTR, CopyType>`
note: required by a bound in `WindowsAndMessaging::LoadCursorA`
    --> C:\Users\Michael\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.52.0\src\Windows\Win32\UI\WindowsAndMessaging\mod.rs:2260:9
     |
2257 | pub unsafe fn LoadCursorA<P0, P1>(hinstance: P0, lpcursorname: P1) -> ::windows_core::Result<HCURSOR>
     |               ----------- required by a bound in this function
...
2260 |     P1: ::windows_core::IntoParam<::windows_core::PCSTR>,
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `LoadCursorA`

Crate manifest

[package]
name = "CursorIssue"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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

Crate code

use windows::Win32::{Foundation::*, UI::WindowsAndMessaging::*};

fn main() {
    unsafe {
        let version = LoadCursorA(HINSTANCE(0), IDC_ARROW); // Does not work
        let wide_version = LoadCursorW(HINSTANCE(0), IDC_ARROW); // Works
    }
}
@mdeforge mdeforge added the bug Something isn't working label Dec 1, 2023
@riverar
Copy link
Collaborator

riverar commented Dec 1, 2023

This is an upstream metadata issue; will transfer there for discussion/resolution.

In the short term, you can use windows::core::PCSTR(32512u16 as _) as a workaround.

@riverar riverar transferred this issue from microsoft/windows-rs Dec 1, 2023
@riverar riverar added broken api An API is inaccurate and could lead to runtime failure rust Critical for Rust adoption and removed bug Something isn't working labels Dec 1, 2023
@mikebattista
Copy link
Contributor

What's the proposed metadata change here?

@riverar
Copy link
Collaborator

riverar commented Dec 5, 2023

Not sure yet, do we have any other examples of how we've incorporated constants into metadata that change (in type), depending on the value of _UNICODE?

@mikebattista
Copy link
Contributor

I don't believe so. We build for UNICODE. In cases where this is an explicit _A variant of the constant, we decorate that variant with the NativeEncoding(ansi) attribute, but I don't recall supporting conditional values for the same constant.

@riverar
Copy link
Collaborator

riverar commented Dec 6, 2023

@mikebattista Hm, looks like we may have to explicitly add both variants with _A/_W suffixes. Still thinking though. 💭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure rust Critical for Rust adoption
Projects
None yet
Development

No branches or pull requests

3 participants