I am trying to make a Window using the WinAPI by following this tutorial. I wrote the following code and used zig build -Dtarget=x86_64-windows-msvc to build the file and linked all the relevant libraries n build.zig.
const std = @import("std");
const c = @cImport({
@cDefine("UNICODE", "");
@cInclude("Windows.h");
});
fn windowProcedure(window: c.HWND, message: c.UINT, wparam: c.WPARAM, lparam: c.LPARAM) callconv(.C) c.LRESULT {
...
}
pub export fn wWinMain(
instance: c.HINSTANCE,
previous_instance: c.HINSTANCE,
command_line: c.LPSTR,
command_show: c.INT,
) callconv(.Win64) c.INT {
...
x}
However, I got these errors.
C:\Program Files\zig\lib\std\start.zig:610:43: error: cast increases pointer alignment
const hInstance = @as(MAIN_HINSTANCE, @ptrCast(peb.ImageBaseAddress));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\zig\lib\std\start.zig:610:55: note: '*os.windows.HMODULE__opaque_55476' has alignment '1'
const hInstance = @as(MAIN_HINSTANCE, @ptrCast(peb.ImageBaseAddress));
~~~^~~~~~~~~~~~~~~~~
C:\Program Files\zig\lib\std\start.zig:610:43: note: '[*c]cimport.struct_HINSTANCE__' has alignment '4'
C:\Program Files\zig\lib\std\start.zig:610:43: note: use @alignCast to assert pointer alignment
C:\Program Files\zig\lib\std\start.zig:548:12: note: called from here
return @call(.always_inline, call_wWinMain, .{});
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\zig\lib\std\start.zig:361:67: note: called from here
const result: std.os.windows.INT = initEventLoopAndCallWinMain(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
How can I get my code to build?