microsoft / microsoft/win32metadata

Cursor related const's are only compatible with LoadCursorW

Open
#1,748 5 comments 0 reactions 0 assignees View on GitHub
broken api rust
Dominant language
C++
Stars
1.5k
Forks
149
Avg merge
5d 16h
Merged PRs (30d)
4

Description

### 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` is not satisfied
--> src\main.rs:5:49
|
5 | let version = LoadCursorA(HINSTANCE(0), IDC_ARROW);
| ----------- ^^^^^^^^^ the trait `CanInto` is not implemented for `PCWSTR`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `CanInto`:
>
>
>
>
>
>
>
>
and 12 others
= note: required for `PCWSTR` to implement `IntoParam`
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(hinstance: P0, lpcursorname: P1) -> ::windows_core::Result
| ----------- required by a bound in this function
...
2260 | P1: ::windows_core::IntoParam<::windows_core::PCSTR>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `LoadCursorA`
```

### Crate manifest

```TOML
[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

```Rust
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
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the generated Windows\Win32\UI\WindowsAndMessaging\mod.rs definitions for IDC_ARROW, LoadCursorA, and LoadCursorW, then reproduce the failure with the Rust crate code shown in the issue. Determine how cursor constants should support both entry points; done means the non-wide and wide calls accept the appropriate cursor constant without breaking the existing wide call.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.