From 60ecf133770b8d00f663239ce4d001ecd15f06c1 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Fri, 4 Aug 2023 11:50:46 +0200 Subject: [PATCH] windows: add TimeBeginPeriod and TimeEndPeriod syscalls Updates golang/go#44343 Fixes golang/go#61723 Change-Id: I920f2fad6b3a2a9ba67ff2fafea4319644a0bc8c Reviewed-on: https://go-review.googlesource.com/c/sys/+/515915 Reviewed-by: qiulaidongfeng <2645477756@qq.com> Run-TryBot: Quim Muntal Reviewed-by: Alex Brainman Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- windows/syscall_windows.go | 4 ++++ windows/syscall_windows_test.go | 9 +++++++++ windows/zsyscall_windows.go | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 373d16388..88e60c876 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -437,6 +437,10 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys DwmGetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, size uint32) (ret error) = dwmapi.DwmGetWindowAttribute //sys DwmSetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, size uint32) (ret error) = dwmapi.DwmSetWindowAttribute +// Windows Multimedia API +//sys TimeBeginPeriod (period uint32) (err error) [failretval != 0] = winmm.timeBeginPeriod +//sys TimeEndPeriod (period uint32) (err error) [failretval != 0] = winmm.timeEndPeriod + // syscall interface implementation for other packages // GetCurrentProcess returns the handle for the current process. diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 25f47ea53..8b51547d1 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -1164,3 +1164,12 @@ items_loop: } } } + +func TestTimePeriod(t *testing.T) { + if err := windows.TimeBeginPeriod(1); err != nil { + t.Fatal(err) + } + if err := windows.TimeEndPeriod(1); err != nil { + t.Fatal(err) + } +} diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 566dd3e31..1c31758ea 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -55,6 +55,7 @@ var ( moduser32 = NewLazySystemDLL("user32.dll") moduserenv = NewLazySystemDLL("userenv.dll") modversion = NewLazySystemDLL("version.dll") + modwinmm = NewLazySystemDLL("winmm.dll") modwintrust = NewLazySystemDLL("wintrust.dll") modws2_32 = NewLazySystemDLL("ws2_32.dll") modwtsapi32 = NewLazySystemDLL("wtsapi32.dll") @@ -468,6 +469,8 @@ var ( procGetFileVersionInfoSizeW = modversion.NewProc("GetFileVersionInfoSizeW") procGetFileVersionInfoW = modversion.NewProc("GetFileVersionInfoW") procVerQueryValueW = modversion.NewProc("VerQueryValueW") + proctimeBeginPeriod = modwinmm.NewProc("timeBeginPeriod") + proctimeEndPeriod = modwinmm.NewProc("timeEndPeriod") procWinVerifyTrustEx = modwintrust.NewProc("WinVerifyTrustEx") procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW") procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW") @@ -4017,6 +4020,22 @@ func _VerQueryValue(block unsafe.Pointer, subBlock *uint16, pointerToBufferPoint return } +func TimeBeginPeriod(period uint32) (err error) { + r1, _, e1 := syscall.Syscall(proctimeBeginPeriod.Addr(), 1, uintptr(period), 0, 0) + if r1 != 0 { + err = errnoErr(e1) + } + return +} + +func TimeEndPeriod(period uint32) (err error) { + r1, _, e1 := syscall.Syscall(proctimeEndPeriod.Addr(), 1, uintptr(period), 0, 0) + if r1 != 0 { + err = errnoErr(e1) + } + return +} + func WinVerifyTrustEx(hwnd HWND, actionId *GUID, data *WinTrustData) (ret error) { r0, _, _ := syscall.Syscall(procWinVerifyTrustEx.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(actionId)), uintptr(unsafe.Pointer(data))) if r0 != 0 {