Skip to content
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

std.os.windows additions and fixes #17705

Merged
merged 1 commit into from
Oct 29, 2023

Conversation

Szwagi
Copy link
Contributor

@Szwagi Szwagi commented Oct 24, 2023

This pull request addresses issues I have found with std.os.windows while using it.

std.os.windows

  • Added PROC type
  • Added HRESULT_CODE macro

std.os.windows.opengl32 (new)

  • Moved wglCreateContext from gdi32
  • Moved wglMakeCurrent from gdi32
  • Fixed wglCreateContext using incorrect types
  • Fixed wglMakeCurrent using incorrect types
  • Added zig wrapper for wglCreateContext
  • Added zig wrapper for wglMakeCurrent
  • Added wglDeleteContext + zig wrapper
  • Added wglGetProcAddress

std.os.windows.dwmapi (new)

  • Added DwmFlush + zig wrapper

std.os.windows.gdi32

  • Added constants required for PIXELFORMATDESCRIPTOR
  • Fixed SetPixelFormat using incorrect types
  • Added zig wrapper for SetPixelFormat
  • Fixed ChoosePixelFormat using incorrect types
  • Added zig wrapper for ChoosePixelFormat
  • Added DescribePixelFormat + zig wrapper
  • Moved wglCreateContext and wglMakeCurrent to opengl32
  • Fixed SwapBuffers using incorrect types
  • Added zig wrapper for SwapBuffers

std.os.windows.kernel32

  • Fixed GetFileAttributesW using incorrect types ([*]const WCHAR instead of [*:0]const WCHAR)
  • Fixed GetProcAddress using incorrect types ([*]const u8 instead of [*:0]const u8)

std.os.windows.user32

  • Added WaitMessage + zig wrapper
  • Added MsgWaitForMultipleObjects + zig wrapper
  • Added GetQueueStatus
  • Added QS_* constants
  • Added MINMAXINFO struct
  • Added SetPropA + zig wrapper
  • Added SetPropW + zig wrapper
  • Added GetPropA
  • Added GetPropW
  • Added GetClientRect + zig wrapper
  • Added GetWindowRect + zig wrapper
  • Added SetWindowPos + zig wrapper
  • Added SWP_* constants
  • Added HWND_* constants
  • Added LoadCursorA + zig wrapper
  • Added LoadCursorW + zig wrapper
  • Added IDC_* cursor constants
  • Added GetSystemMetrics
  • Added GetSystemMetricsForDpi + zig wrapper
  • Added SM_* constants
  • Added ARW_* constants
  • Added NID_* constants

I am unsure about the names for opengl32 zig wrappers. The convention seems to be using lowercase, but wgl* functions are already lowercase, so I added a "Z" at the end for now. Perhaps removing the wgl prefix and using lowercase is the way to go?

I am also unsure about the IDC_ constants. In C they are casted into the correct type (LPCSTR, LPCWSTR) depending on the defined character set. Currently passing them to LoadCursor* requires @ptrFromInt(IDC_*).

Note that I am an on-and-off unexperienced Zig user, and a first time contributor, so I hope I didn't butcher any of the syntax.

@squeek502
Copy link
Collaborator

squeek502 commented Oct 24, 2023

Just a heads up: the fixes are much more likely to be merged than the additions, unless there's a use-case within the standard library or the Zig compiler source code.

Relevant issues:

Note also that the added bindings do not have to be part of the standard library for you to be able to use them. They can go in your project's source and it'll work just fine.

EDIT: Personally, I think it might make sense for Zig's standard library to contain definitions for all types that are defined using opaque{} to allow for interoperability, though.

@squeek502
Copy link
Collaborator

With user32.zig getting deleted in #17763, I think the best way forward would be to trim this down to just windows.zig additions/kernel32.zig fixes.

@Szwagi Szwagi force-pushed the windows-additions-and-fixes branch from 3604d89 to 80aad4c Compare October 29, 2023 01:55
@Vexu Vexu merged commit 3729569 into ziglang:master Oct 29, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants