devicescale: Use runtime.KeepAlive for Windows

This might be related to the bug #832
This commit is contained in:
Hajime Hoshi 2019-04-03 11:53:20 +09:00
parent ba033ddf20
commit 8005682786

View File

@ -18,6 +18,7 @@ package devicescale
import ( import (
"fmt" "fmt"
"runtime"
"unsafe" "unsafe"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
@ -136,8 +137,9 @@ func getDeviceCaps(hdc uintptr, nindex int) (int, error) {
return int(r), nil return int(r), nil
} }
func monitorFromRect(lprc uintptr, dwFlags int) (uintptr, error) { func monitorFromRect(lprc *rect, dwFlags int) (uintptr, error) {
r, _, e := procMonitorFromRect.Call(lprc, uintptr(dwFlags)) r, _, e := procMonitorFromRect.Call(uintptr(unsafe.Pointer(lprc)), uintptr(dwFlags))
runtime.KeepAlive(lprc)
if e != nil && e.(windows.Errno) != 0 { if e != nil && e.(windows.Errno) != 0 {
return 0, &winErr{ return 0, &winErr{
FuncName: "MonitorFromRect", FuncName: "MonitorFromRect",
@ -238,7 +240,7 @@ func impl(x, y int) float64 {
// MonitorFromPoint requires to pass a POINT value, and there seems no portable way to // MonitorFromPoint requires to pass a POINT value, and there seems no portable way to
// do this with Cgo. Use MonitorFromRect instead. // do this with Cgo. Use MonitorFromRect instead.
m, err := monitorFromRect(uintptr(unsafe.Pointer(&lprc)), monitorDefaultToNearest) m, err := monitorFromRect(&lprc, monitorDefaultToNearest)
if err != nil { if err != nil {
panic(err) panic(err)
} }