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
MAKEINTRESOURCE integers should be 16-bit not 32-bit #1029
Comments
This is a bug on win32metadata / me. We should be treating MAKEINTRESOURCE integers as WORDs (16-bit). Will transfer. |
|
I don't agree that MAKEINTRESOURCE values should be 16-bit. They're passed to functions that are expecting a LPCWSTR or LPSTR. But I don't know enough about the rust projection to know why the repro steps failed to compile. It seems like they should have worked. |
@sotteson1 The MAKEINTRESOURCE macros (see above) cast to WORD before doing additional arithmetic. IS_INTRESOURCE also shifts right 16 bits. Am I missing something? |
The final cast is to a string. They are meant to be used in functions that take a string. |
IS_INTRESOURCE takes a string and sees if the high word is 0. If it is, you know it’s a 16-bit int resource that has been cast to a string to be used in the resource functions. |
I'm not sure this is a metadata bug - the metadata represents this as follows: public const PWSTR TD_WARNING_ICON = -1; This is completely invalid but also a fairly accurate representation of what the Windows SDK declares. It may be up to the languages to coerce this properly. |
When I said we should treat "MAKEINTRESOURCE integers as WORDs" in the original issue, I was referring to the integer input into the macro. Right now, when we scrape |
Makes sense. |
Oh, that makes sense. We should fix that. |
For curious minds, that |
Thanks for the analysis @riverar - in the meantime I have a workaround here: microsoft/windows-rs#2007 |
Is the fix here just to cast to ushort below?
Or does the fix need to be plumbed through in more places? |
@riverar any pointers here on the fix? |
@mikebattista That sounds right, let's see if we can get a test wired up to verify. We'll need to fix up that call to AddInteger downstream too. Should have this wrapped up soon. |
So I've made some changes that now emits the constant as
|
Reopening as these constants need to be unsigned to avoid sign extension. |
Yep, my dumb mistake. (I even mentioned sign extension smacks head.) Will fix now. |
Which crate is this about?
windows
Crate version
0.39
Summary
TD_WARNING_ICON
was missing in older version and introduced in v0.39 (REF: #968), but it seems that the value (PCWSTR(-1i32 as _)
) is not correct and can causeSTATUS_ACCESS_VIOLATION
error when running.Instead, use
PCWSTR(-1i32 as u16 as _)
would work correctly.Toolchain version/configuration
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\berto.rustup
installed targets for active toolchain
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
active toolchain
stable-x86_64-pc-windows-msvc (default)
rustc 1.61.0 (fe5b13d68 2022-05-18)
Reproducible example
git@github.com:PolyMeilex/rfd.git
PCWSTR(main_icon_ptr as *const u16)
withwindows::Win32::UI::Controls::TD_WARNING_ICON
examples/message-custom-buttons
Crate manifest
No response
Expected behavior
Should show a task dialog
Actual behavior
error: process didn't exit successfully:
target\debug\message-custom-buttons.exe
(exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)Additional comments
No response
The text was updated successfully, but these errors were encountered: