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

DEVMODE structure has fields with incorrect types #1325

Closed
Skrity opened this issue Oct 22, 2022 · 9 comments · Fixed by #1329
Closed

DEVMODE structure has fields with incorrect types #1325

Skrity opened this issue Oct 22, 2022 · 9 comments · Fixed by #1329
Assignees
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working

Comments

@Skrity
Copy link

Skrity commented Oct 22, 2022

Which crate is this about?

windows

Crate version

0.42.0

Summary

When querying display via EnumDisplaySettings(A,W,ExA,ExW) display parameters get inserted into wrong fields. Tested on 2 pcs so far.

Toolchain version/configuration

Default host: x86_64-pc-windows-gnu
rustup home: C:_scoop\persist\rustup.rustup

stable-x86_64-pc-windows-gnu (default)
rustc 1.64.0 (a55dd71d5 2022-09-19)

Reproducible example

fn main() {
    use windows::Win32::Graphics::Gdi::*;
    let mut dm = DEVMODEA::default();
    dm.dmSize = std::mem::size_of_val(&dm) as u16;
    let b = unsafe {EnumDisplaySettingsExA(windows::core::PCSTR::null(), ENUM_CURRENT_SETTINGS, &mut dm, 0u32) };
    println!("Result: {:?}",b);
    println!("dmBitsPerPel: {:?}", dm.dmBitsPerPel);
    println!("dmPelsWidth: {:?}", dm.dmPelsWidth);
    println!("dmPelsHeight: {:?}", dm.dmPelsHeight);
    println!("dmDisplayFrequency: {:?}", dm.dmDisplayFrequency);
    println!("others");
    println!("dmSpecVersion: {:?}", dm.dmSpecVersion);
    println!("dmDriverVersion: {:?}", dm.dmDriverVersion);
    println!("dmDriverExtra: {:?}", dm.dmDriverExtra);
    println!("dmLogPixels: {:?}", dm.dmLogPixels);
    println!("dmICMMethod: {:?}", dm.dmICMMethod);
}

Crate manifest

[package]
name = "test_refresh"
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.42.0"
features = ["Win32_Foundation", "Win32_Graphics_Gdi"]

Expected behavior

Result: BOOL(1)
dmBitsPerPel: *
dmPelsWidth: 2560
dmPelsHeight: 1440
dmDisplayFrequency: 165
others
dmSpecVersion: *
dmDriverVersion: *
dmDriverExtra: *
dmLogPixels: *
dmICMMethod: *

Actual behavior

Result: BOOL(1)
dmBitsPerPel: 1440
dmPelsWidth: 0
dmPelsHeight: 165
dmDisplayFrequency: 0
others
dmSpecVersion: 1025
dmDriverVersion: 1025
dmDriverExtra: 0
dmLogPixels: 2560
dmICMMethod: 0

Additional comments

No response

@Skrity Skrity added the bug Something isn't working label Oct 22, 2022
@riverar
Copy link
Collaborator

riverar commented Oct 22, 2022

Thanks @Skrity, looks like several struct members are incorrectly defined in metadata (DEVMODE_COLOR, DEVMODE_TRUETYPE_OPTION, DEVMODE_COLLATE). Transferring over there!

@riverar riverar transferred this issue from microsoft/windows-rs Oct 22, 2022
@riverar riverar changed the title Bug: EnumDisplaySettingsA populates wrong fields DEVMODE structure has fields with incorrect types Oct 22, 2022
@mikebattista mikebattista added the broken api An API is inaccurate and could lead to runtime failure label Oct 24, 2022
@mikebattista
Copy link
Collaborator

Can you clarify what's broken here? Is the struct defined incorrectly? Or is the API for some reason returning the wrong values?

@riverar you mentioned some enums but the repro doesn't mention any fields that use these enums.

@riverar
Copy link
Collaborator

riverar commented Oct 24, 2022

@mikebattista At a quick glance, it appears DEVMODE_COLOR, DEVMODE_TRUETYPE_OPTION, DEVMODE_COLLATE are defined as uint but should be ushort. Depending on the packing, it could be throwing off subsequent fields. Haven't fully triaged this, but the size of the struct in Rust (164 bytes) doesn't match C++ (156 bytes).

If you don't beat me to it, I can possibly take a look later in the evenings.

@mikebattista
Copy link
Collaborator

Since you're more familiar with the Rust toolchain, I'll assign to you to make the type changes in enums.json and validate the Rust repro.

@kennykerr
Copy link
Contributor

Since this isn't specific to Rust, it would be great if you have some kind of build validation that compared all struct sizes in metadata against MSVC.

@riverar
Copy link
Collaborator

riverar commented Oct 26, 2022

Thanks @Skrity, should see this trickle into the next Rust crate update

@kennykerr
Copy link
Contributor

The DEVMODEA/DEVMODEW structs, in the Windows.Win32.Graphics.Gdi namespace, now have dependencies on the types in the Windows.Win32.System.SystemServices namespace e.g. DEVMODE_DISPLAY_ORIENTATION and DEVMODE_DISPLAY_FIXED_OUTPUT. That seems wrong.

@kennykerr kennykerr reopened this Nov 2, 2022
@mikebattista
Copy link
Collaborator

Yes that's a bug. I will fix.

@mikebattista mikebattista assigned mikebattista and unassigned riverar Nov 2, 2022
@mikebattista
Copy link
Collaborator

Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_FIXED_OUTPUT added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_FIXED_OUTPUT.DMDFO_CENTER added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_FIXED_OUTPUT.DMDFO_DEFAULT added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_FIXED_OUTPUT.DMDFO_STRETCH added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION.DMDO_180 added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION.DMDO_270 added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION.DMDO_90 added
Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION.DMDO_DEFAULT added
Windows.Win32.Graphics.Gdi.DEVMODEA._Anonymous1_e__Union._Anonymous2_e__Struct.dmDisplayFixedOutput...Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_FIXED_OUTPUT => Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_FIXED_OUTPUT
Windows.Win32.Graphics.Gdi.DEVMODEA._Anonymous1_e__Union._Anonymous2_e__Struct.dmDisplayOrientation...Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION => Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION
Windows.Win32.Graphics.Gdi.DEVMODEW._Anonymous1_e__Union._Anonymous2_e__Struct.dmDisplayFixedOutput...Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_FIXED_OUTPUT => Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_FIXED_OUTPUT
Windows.Win32.Graphics.Gdi.DEVMODEW._Anonymous1_e__Union._Anonymous2_e__Struct.dmDisplayOrientation...Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION => Windows.Win32.Graphics.Gdi.DEVMODE_DISPLAY_ORIENTATION
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_FIXED_OUTPUT removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_FIXED_OUTPUT.DMDFO_CENTER removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_FIXED_OUTPUT.DMDFO_DEFAULT removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_FIXED_OUTPUT.DMDFO_STRETCH removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION.DMDO_180 removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION.DMDO_270 removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION.DMDO_90 removed
Windows.Win32.System.SystemServices.DEVMODE_DISPLAY_ORIENTATION.DMDO_DEFAULT removed

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 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants