Open ofrank123 opened 5 months ago
There are reasons including windows.h does not work (perhaps someone can elaborate why).
The following may be of interest to you: https://www.youtube.com/watch?v=HsnWZxrf5VE https://github.com/marlersoft/zigwin32
I am not sure if the solution for interfacing with windows as described there, has been kept up to date all the way up to the present.
It works fine using mingw in my experience, does mingw ship their own windows.h? But thanks for the links, I'll check it out
As a workaround, you can write bindings for the APIs you need, similar to those in the standard library:
https://github.com/ziglang/zig/blob/master/lib/std/os/windows/kernel32.zig#L72
or you can use https://github.com/marlersoft/zigwin32/ for autogenerated bindings.
The benefit of this approach is that you no longer need to link libc (if you're only linking it for windows.h
), and your program will only depend on the DLLs that it actually uses.
Thanks @squeek502, that's a good point. It'd be nice not to have to depend on libc as I don't really use it. I'll look into moving my codebase to use this strategy.
@ofrank123 yes, mingw ships their own headers. the reason this only happens on msvc & not mingw is because the windows SDK defines MIDL_INTERFACE
like so:
#define MIDL_INTERFACE(x) struct DECLSPEC_UUID(x) DECLSPEC_NOVTABLE
while mingw just defines it as struct
. as a simple workaround, if you define MIDL_INTERFACE
like mingw does:
zig build-exe -target x86_64-windows-msvc -DMIDL_INTERFACE=struct -lc .\test.zig
then code that imports windows.h
compiles fine.
Thanks for the heads up @nihil-2019!
Note: you can add @cDefine("MIDL_INTERFACE", "struct");
inside your @cImport({});
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
The following program:
Fails to compile, using
zig run -target x86_64-windows-msvc -lc .\main.zig
:Expected Behavior
It should compile