devicescale: Remove 'syscall' package usages (#766)

This commit is contained in:
Hajime Hoshi 2019-01-04 05:53:18 +09:00
parent f2840bb0dc
commit 5c1b0bbcec

View File

@ -18,8 +18,9 @@ package devicescale
import ( import (
"fmt" "fmt"
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/windows"
) )
const ( const (
@ -36,9 +37,9 @@ type rect struct {
} }
var ( var (
user32 = syscall.NewLazyDLL("user32") user32 = windows.NewLazyDLL("user32")
gdi32 = syscall.NewLazyDLL("gdi32") gdi32 = windows.NewLazyDLL("gdi32")
shcore = syscall.NewLazyDLL("shcore") shcore = windows.NewLazyDLL("shcore")
) )
var ( var (
@ -59,7 +60,7 @@ var shcoreAvailable = false
type winErr struct { type winErr struct {
FuncName string FuncName string
Code syscall.Errno Code windows.Errno
Return uintptr Return uintptr
} }
@ -74,11 +75,11 @@ func init() {
} }
func setProcessDPIAware() error { func setProcessDPIAware() error {
r, _, e := syscall.Syscall(procSetProcessDPIAware.Addr(), 0, 0, 0, 0) r, _, e := procSetProcessDPIAware.Call()
if e != 0 { if e != nil && e.(windows.Errno) != 0 {
return &winErr{ return &winErr{
FuncName: "SetProcessDPIAware", FuncName: "SetProcessDPIAware",
Code: e, Code: e.(windows.Errno),
} }
} }
if r == 0 { if r == 0 {
@ -91,11 +92,11 @@ func setProcessDPIAware() error {
} }
func getWindowDC(hwnd uintptr) (uintptr, error) { func getWindowDC(hwnd uintptr) (uintptr, error) {
r, _, e := syscall.Syscall(procGetWindowDC.Addr(), 1, hwnd, 0, 0) r, _, e := procGetWindowDC.Call(hwnd)
if e != 0 { if e != nil && e.(windows.Errno) != 0 {
return 0, &winErr{ return 0, &winErr{
FuncName: "GetWindowDC", FuncName: "GetWindowDC",
Code: e, Code: e.(windows.Errno),
} }
} }
if r == 0 { if r == 0 {
@ -108,11 +109,11 @@ func getWindowDC(hwnd uintptr) (uintptr, error) {
} }
func releaseDC(hwnd, hdc uintptr) error { func releaseDC(hwnd, hdc uintptr) error {
r, _, e := syscall.Syscall(procReleaseDC.Addr(), 2, hwnd, hdc, 0) r, _, e := procReleaseDC.Call(hwnd, hdc)
if e != 0 { if e != nil && e.(windows.Errno) != 0 {
return &winErr{ return &winErr{
FuncName: "ReleaseDC", FuncName: "ReleaseDC",
Code: e, Code: e.(windows.Errno),
} }
} }
if r == 0 { if r == 0 {
@ -125,22 +126,22 @@ func releaseDC(hwnd, hdc uintptr) error {
} }
func getDeviceCaps(hdc uintptr, nindex int) (int, error) { func getDeviceCaps(hdc uintptr, nindex int) (int, error) {
r, _, e := syscall.Syscall(procGetDeviceCaps.Addr(), 2, hdc, uintptr(nindex), 0) r, _, e := procGetDeviceCaps.Call(hdc, uintptr(nindex))
if e != 0 { if e != nil && e.(windows.Errno) != 0 {
return 0, &winErr{ return 0, &winErr{
FuncName: "GetDeviceCaps", FuncName: "GetDeviceCaps",
Code: e, Code: e.(windows.Errno),
} }
} }
return int(r), nil return int(r), nil
} }
func monitorFromRect(lprc uintptr, dwFlags int) (uintptr, error) { func monitorFromRect(lprc uintptr, dwFlags int) (uintptr, error) {
r, _, e := syscall.Syscall(procMonitorFromRect.Addr(), 2, lprc, uintptr(dwFlags), 0) r, _, e := procMonitorFromRect.Call(lprc, uintptr(dwFlags))
if e != 0 { if e != nil && e.(windows.Errno) != 0 {
return 0, &winErr{ return 0, &winErr{
FuncName: "MonitorFromRect", FuncName: "MonitorFromRect",
Code: e, Code: e.(windows.Errno),
} }
} }
if r == 0 { if r == 0 {
@ -153,11 +154,11 @@ func monitorFromRect(lprc uintptr, dwFlags int) (uintptr, error) {
} }
func getMonitorInfo(hMonitor uintptr, lpMonitorInfo uintptr) error { func getMonitorInfo(hMonitor uintptr, lpMonitorInfo uintptr) error {
r, _, e := syscall.Syscall(procGetMonitorInfo.Addr(), 2, hMonitor, lpMonitorInfo, 0) r, _, e := procGetMonitorInfo.Call(hMonitor, lpMonitorInfo)
if e != 0 { if e != nil && e.(windows.Errno) != 0 {
return &winErr{ return &winErr{
FuncName: "GetMonitorInfo", FuncName: "GetMonitorInfo",
Code: e, Code: e.(windows.Errno),
} }
} }
if r == 0 { if r == 0 {
@ -170,12 +171,11 @@ func getMonitorInfo(hMonitor uintptr, lpMonitorInfo uintptr) error {
} }
func getDpiForMonitor(hMonitor uintptr, dpiType uintptr, dpiX, dpiY uintptr) error { func getDpiForMonitor(hMonitor uintptr, dpiType uintptr, dpiX, dpiY uintptr) error {
r, _, e := syscall.Syscall6(procGetDpiForMonitor.Addr(), 4, r, _, e := procGetDpiForMonitor.Call(hMonitor, dpiType, dpiX, dpiY)
hMonitor, dpiType, dpiX, dpiY, 0, 0) if e != nil && e.(windows.Errno) != 0 {
if e != 0 {
return &winErr{ return &winErr{
FuncName: "GetDpiForMonitor", FuncName: "GetDpiForMonitor",
Code: e, Code: e.(windows.Errno),
} }
} }
if r != 0 { if r != 0 {