Skip to content

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

@Tired-Fox

Description

@Tired-Fox

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions