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

Make load functions for window resources take [*:0]align(1) const u16 #29

Open
Tired-Fox opened this issue Apr 8, 2024 · 0 comments
Open

Comments

@Tired-Fox
Copy link

Currently methods like LoadCursorW and LoadIconW require [*:0]const u16. However, the preferred method to get the u16 string for the cursor or icon, with MakeIntResourceW, can only be done with [*:0]align(1) const u16. It seems that the constants after IDI_APPLICATION and IDC_ARROW are commented out because the pointers are aligned to 1 instead of 2 and cause an error.

Is it reasonable to make any function that takes a [*:0]const u16 that is meant to be use with MakeIntResourceW take [*:0]align(1) const 16 instead?

The signature would change to the following.

pub extern "user32" fn LoadCursorW(
    hInstance: ?HINSTANCE,
    lpCursorName: ?[*:0]align(1) const u16,
) callconv(@import("std").os.windows.WINAPI) ?HCURSOR;

Recreation of MakeIntResourceW

fn makeIntResourceW(comptime resource: usize) [*:0]align(1) const u16 {
    // This cast requires that the u16 array is aligned to 1
    return @ptrFromInt(usize_value);
}

Can also be the below code since that is what is used in the library

const IDC_HAND = @import("zig.zig").typedConst([*:0]align(1) const u16, @as(u32, 32649))

I added the signature in my local library and it fixes the issue and allows for all the constants to be assigned.
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant