Hi! I am currently making a simple windowing library, and am working on the win32 part of it now. I have run into an issue that I have struggles with overcoming.
I am writing my own user32.zig implementation, and with that I am trying to convert the original MAKEINTRESOURCE macro from MINGW winuser.h, which you can see here:
This works fine for the makeIntResourceA function, since the LPCSTR just has a 1 byte alignment, the issues is when I am trying to use the makeIntResourceW function.
The makeIntResourceW works fine with values such as IDC_ARROW = 32512 because that has a 2 byte alignment, but with icons such as IDC_BEAM=32513 I get the following error, understandably.
This code is then later used from my window implementation and is passed to the win32 LoadCursorW function. My question then becomes how can I even do something like this in Zig, or do I have to write my own winuser.h file that only includes the constants and the macro and use that instead?
While LPCWSTR declaration remains the same, zig type system is not going to let you have a misaligned value.
You can use MAKEINTRESOURCEA with LoadCursorA, and use LoadCursorW when you have a string name.
Another option is to make ResourceNamePtr an *opaque {} which means that you’d have to @ptrCast string names when calling the Load functions, but would make it so that you wouldn’t need separate makeIntResourceA/makeIntResourceW functions.