-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
A win32-api proposal, implemented for user32.zig #7195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the whole pattern with selectSymbol
forces all function calls to be indirect? This would seem to be undesireable....
@@ -52,13 +86,21 @@ pub const WM_SYSKEYDOWN = 0x0104; | |||
pub const WM_SYSKEYUP = 0x0105; | |||
pub const WM_SYSCHAR = 0x0106; | |||
pub const WM_SYSDEADCHAR = 0x0107; | |||
pub const WM_UNICHAR = 0x0109; | |||
pub const WM_KEYLAST = 0x0109; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you want to include most of the *LAST
definitions: they merely state that this is the next free enum member, and it will likely change in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys are a subset of the WM_
constants, so knowing what the last key or mouse event is specifically might still be useful.
Seems to me like the optimizer takes care of it: |
Co-authored-by: daurnimator <[email protected]>
pub const MB_MODEMASK = 0x00003000; | ||
pub const MB_MISCMASK = 0x0000C000; | ||
|
||
pub const IDOK = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it should be an enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm copying the values from the Windows headers, where they are not.
I could certainly convert a lot of the values to enums and such, though it might annoy people following the Windows documentation and assuming it'll look identical.
Unless I'm missing something, I thought the idea was to totally get rid of higher-level Win API such as |
For many tasks using |
Right, but I thought that was the point of not having any dependence on higher-level APIs whatsoever - to manage it ourselves within Zig's libstd using only the |
I'm not advocating for uprooting #1840 and using kernel32 instead of ntdll in the standard library. 🙂 |
I don't think we've established a criteria for what goes in the standard library, but my guess is we'll use something like this to determine whether it goes into the standard library:
There could be other tools we want to include in this list. For the Windows bindings., I think the direction we want to go is keep the full set of Windows bindings in project outside the standard library. That's why I recently started this project: https://github.com/marler8997/zig-os-windows The goal of my zig-os-windows project is to be able to autogenerate the bindings from a data set representing the API. In the README.md I talk more about direction/goals. One question is how to handle Zig wrappers for the Windows API like you've created here. I'm not sure how hard it will be to autogenerate those as well, but because of the size of the Windows API I think it's worth exploring this option. By autogenerating the bindings as well, we can generate bindings with different options like normalizing data types to Zig types, organizing by C header or by DLL, etc. One option is to not only generate a full set of bindings, but also a subset needed in the standard library. |
Noting that #1840 is still the accepted way forward for the standard library (std lib should only depend on ntdll.dll) and #4426 looming in the future (user32.zig may be deleted from the std lib after all), I think this proposal is appropriate to be accepted as the path forward, for whatever Windows bindings we decide to maintain in the standard library. So I'm happy to merge this and accept this proposal now, with the understanding that (1) the standard library should avoid depending on user32.dll entirely and (2) we may eventually delete all this code anyway (or move it to the standard library orphanage). |
u32
instead ofULONG
(yes, these are always the same on Windows!)If the entire OS target range you are compiling for includes the function, it calls the plain function.
If the OS target range you are compiling for partially includes the function, it calls a function pointer. It is the responsibility of the caller to load this beforehand.
SetWindowLongPtrA
is typedefed toSetWindowLongA
for 32-bit architectures, so we call that functions instead if so. It also requires you to do aSetLastError(ERROR_SUCCESS)
before you call it, as it doesn't do that by itself. The wrapper does, as otherwise we'd have no idea if an error is real or a remnant from the previous function call.bits.zig
, everything else is defined above the family of functions that uses it.OpenFile
/CreateFile
.