Commit 95429d82 authored by Jaroslavas Počepko's avatar Jaroslavas Počepko Committed by Alex Brainman

exp/wingui: made compatible with windows/amd64

R=golang-dev, alex.brainman
CC=golang-dev, vcc.163
https://golang.org/cl/4974041
parent 7349d21f
...@@ -25,13 +25,12 @@ func abortErrNo(funcname string, err int) { ...@@ -25,13 +25,12 @@ func abortErrNo(funcname string, err int) {
// global vars // global vars
var ( var (
mh uint32 mh syscall.Handle
bh uint32 bh syscall.Handle
) )
// WinProc called by windows to notify us of all windows events we might be interested in. // WinProc called by windows to notify us of all windows events we might be interested in.
func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr { func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
var rc int32
switch msg { switch msg {
case WM_CREATE: case WM_CREATE:
var e int var e int
...@@ -49,7 +48,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr { ...@@ -49,7 +48,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
fmt.Printf("button handle is %x\n", bh) fmt.Printf("button handle is %x\n", bh)
rc = DefWindowProc(hwnd, msg, wparam, lparam) rc = DefWindowProc(hwnd, msg, wparam, lparam)
case WM_COMMAND: case WM_COMMAND:
switch uint32(lparam) { switch syscall.Handle(lparam) {
case bh: case bh:
e := PostMessage(hwnd, WM_CLOSE, 0, 0) e := PostMessage(hwnd, WM_CLOSE, 0, 0)
if e != 0 { if e != 0 {
...@@ -66,7 +65,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr { ...@@ -66,7 +65,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
rc = DefWindowProc(hwnd, msg, wparam, lparam) rc = DefWindowProc(hwnd, msg, wparam, lparam)
} }
//fmt.Printf("WndProc(0x%08x, %d, 0x%08x, 0x%08x) (%d)\n", hwnd, msg, wparam, lparam, rc) //fmt.Printf("WndProc(0x%08x, %d, 0x%08x, 0x%08x) (%d)\n", hwnd, msg, wparam, lparam, rc)
return uintptr(rc) return
} }
func rungui() int { func rungui() int {
......
...@@ -6,6 +6,7 @@ package main ...@@ -6,6 +6,7 @@ package main
import ( import (
"unsafe" "unsafe"
"syscall"
) )
type Wndclassex struct { type Wndclassex struct {
...@@ -14,25 +15,25 @@ type Wndclassex struct { ...@@ -14,25 +15,25 @@ type Wndclassex struct {
WndProc uintptr WndProc uintptr
ClsExtra int32 ClsExtra int32
WndExtra int32 WndExtra int32
Instance uint32 Instance syscall.Handle
Icon uint32 Icon syscall.Handle
Cursor uint32 Cursor syscall.Handle
Background uint32 Background syscall.Handle
MenuName *uint16 MenuName *uint16
ClassName *uint16 ClassName *uint16
IconSm uint32 IconSm syscall.Handle
} }
type Point struct { type Point struct {
X int32 X uintptr
Y int32 Y uintptr
} }
type Msg struct { type Msg struct {
Hwnd uint32 Hwnd syscall.Handle
Message uint32 Message uint32
Wparam int32 Wparam uintptr
Lparam int32 Lparam uintptr
Time uint32 Time uint32
Pt Point Pt Point
} }
...@@ -109,22 +110,22 @@ var ( ...@@ -109,22 +110,22 @@ var (
IDI_INFORMATION = IDI_ASTERISK IDI_INFORMATION = IDI_ASTERISK
) )
//sys GetModuleHandle(modname *uint16) (handle uint32, errno int) = GetModuleHandleW //sys GetModuleHandle(modname *uint16) (handle syscall.Handle, errno int) = GetModuleHandleW
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW //sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW
//sys CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent uint32, menu uint32, instance uint32, param uintptr) (hwnd uint32, errno int) = user32.CreateWindowExW //sys CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, errno int) = user32.CreateWindowExW
//sys DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.DefWindowProcW //sys DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.DefWindowProcW
//sys DestroyWindow(hwnd uint32) (errno int) = user32.DestroyWindow //sys DestroyWindow(hwnd syscall.Handle) (errno int) = user32.DestroyWindow
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage //sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
//sys ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) = user32.ShowWindow //sys ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) = user32.ShowWindow
//sys UpdateWindow(hwnd uint32) (errno int) = user32.UpdateWindow //sys UpdateWindow(hwnd syscall.Handle) (errno int) = user32.UpdateWindow
//sys GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW //sys GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage //sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW //sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
//sys LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) = user32.LoadIconW //sys LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, errno int) = user32.LoadIconW
//sys LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) = user32.LoadCursorW //sys LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, errno int) = user32.LoadCursorW
//sys SetCursor(cursor uint32) (precursor uint32, errno int) = user32.SetCursor //sys SetCursor(cursor syscall.Handle) (precursor syscall.Handle, errno int) = user32.SetCursor
//sys SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.SendMessageW //sys SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.SendMessageW
//sys PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) = user32.PostMessageW //sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (errno int) = user32.PostMessageW
func MakeIntResource(id uint16) *uint16 { func MakeIntResource(id uint16) *uint16 {
return (*uint16)(unsafe.Pointer(uintptr(id))) return (*uint16)(unsafe.Pointer(uintptr(id)))
......
...@@ -28,9 +28,9 @@ var ( ...@@ -28,9 +28,9 @@ var (
procPostMessageW = moduser32.NewProc("PostMessageW") procPostMessageW = moduser32.NewProc("PostMessageW")
) )
func GetModuleHandle(modname *uint16) (handle uint32, errno int) { func GetModuleHandle(modname *uint16) (handle syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0) r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0)
handle = uint32(r0) handle = syscall.Handle(r0)
if handle == 0 { if handle == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
...@@ -58,9 +58,9 @@ func RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) { ...@@ -58,9 +58,9 @@ func RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) {
return return
} }
func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent uint32, menu uint32, instance uint32, param uintptr) (hwnd uint32, errno int) { func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall12(procCreateWindowExW.Addr(), 12, uintptr(exstyle), uintptr(unsafe.Pointer(classname)), uintptr(unsafe.Pointer(windowname)), uintptr(style), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(wndparent), uintptr(menu), uintptr(instance), uintptr(param)) r0, _, e1 := syscall.Syscall12(procCreateWindowExW.Addr(), 12, uintptr(exstyle), uintptr(unsafe.Pointer(classname)), uintptr(unsafe.Pointer(windowname)), uintptr(style), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(wndparent), uintptr(menu), uintptr(instance), uintptr(param))
hwnd = uint32(r0) hwnd = syscall.Handle(r0)
if hwnd == 0 { if hwnd == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
...@@ -73,13 +73,13 @@ func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style ...@@ -73,13 +73,13 @@ func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style
return return
} }
func DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) { func DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) {
r0, _, _ := syscall.Syscall6(procDefWindowProcW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0) r0, _, _ := syscall.Syscall6(procDefWindowProcW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = int32(r0) lresult = uintptr(r0)
return return
} }
func DestroyWindow(hwnd uint32) (errno int) { func DestroyWindow(hwnd syscall.Handle) (errno int) {
r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0) r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 { if int(r1) == 0 {
if e1 != 0 { if e1 != 0 {
...@@ -98,13 +98,13 @@ func PostQuitMessage(exitcode int32) { ...@@ -98,13 +98,13 @@ func PostQuitMessage(exitcode int32) {
return return
} }
func ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) { func ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) {
r0, _, _ := syscall.Syscall(procShowWindow.Addr(), 2, uintptr(hwnd), uintptr(cmdshow), 0) r0, _, _ := syscall.Syscall(procShowWindow.Addr(), 2, uintptr(hwnd), uintptr(cmdshow), 0)
wasvisible = bool(r0 != 0) wasvisible = bool(r0 != 0)
return return
} }
func UpdateWindow(hwnd uint32) (errno int) { func UpdateWindow(hwnd syscall.Handle) (errno int) {
r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0) r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 { if int(r1) == 0 {
if e1 != 0 { if e1 != 0 {
...@@ -118,7 +118,7 @@ func UpdateWindow(hwnd uint32) (errno int) { ...@@ -118,7 +118,7 @@ func UpdateWindow(hwnd uint32) (errno int) {
return return
} }
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) { func GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) {
r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0) r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
ret = int32(r0) ret = int32(r0)
if ret == -1 { if ret == -1 {
...@@ -145,9 +145,9 @@ func DispatchMessage(msg *Msg) (ret int32) { ...@@ -145,9 +145,9 @@ func DispatchMessage(msg *Msg) (ret int32) {
return return
} }
func LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) { func LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procLoadIconW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0) r0, _, e1 := syscall.Syscall(procLoadIconW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0)
icon = uint32(r0) icon = syscall.Handle(r0)
if icon == 0 { if icon == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
...@@ -160,9 +160,9 @@ func LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) { ...@@ -160,9 +160,9 @@ func LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) {
return return
} }
func LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) { func LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procLoadCursorW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0) r0, _, e1 := syscall.Syscall(procLoadCursorW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0)
cursor = uint32(r0) cursor = syscall.Handle(r0)
if cursor == 0 { if cursor == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
...@@ -175,9 +175,9 @@ func LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) ...@@ -175,9 +175,9 @@ func LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int)
return return
} }
func SetCursor(cursor uint32) (precursor uint32, errno int) { func SetCursor(cursor syscall.Handle) (precursor syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0) r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0)
precursor = uint32(r0) precursor = syscall.Handle(r0)
if precursor == 0 { if precursor == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
...@@ -190,13 +190,13 @@ func SetCursor(cursor uint32) (precursor uint32, errno int) { ...@@ -190,13 +190,13 @@ func SetCursor(cursor uint32) (precursor uint32, errno int) {
return return
} }
func SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) { func SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) {
r0, _, _ := syscall.Syscall6(procSendMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0) r0, _, _ := syscall.Syscall6(procSendMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = int32(r0) lresult = uintptr(r0)
return return
} }
func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) { func PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (errno int) {
r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0) r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
if int(r1) == 0 { if int(r1) == 0 {
if e1 != 0 { if e1 != 0 {
......
...@@ -158,7 +158,7 @@ func NewCallback(fn interface{}) uintptr ...@@ -158,7 +158,7 @@ func NewCallback(fn interface{}) uintptr
//sys GetLastError() (lasterrno int) //sys GetLastError() (lasterrno int)
//sys LoadLibrary(libname string) (handle Handle, errno int) = LoadLibraryW //sys LoadLibrary(libname string) (handle Handle, errno int) = LoadLibraryW
//sys FreeLibrary(handle Handle) (errno int) //sys FreeLibrary(handle Handle) (errno int)
//sys GetProcAddress(module Handle, procname string) (proc Handle, errno int) //sys GetProcAddress(module Handle, procname string) (proc uintptr, errno int)
//sys GetVersion() (ver uint32, errno int) //sys GetVersion() (ver uint32, errno int)
//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, errno int) = FormatMessageW //sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, errno int) = FormatMessageW
//sys ExitProcess(exitcode uint32) //sys ExitProcess(exitcode uint32)
......
...@@ -141,9 +141,8 @@ func FreeLibrary(handle Handle) (errno int) { ...@@ -141,9 +141,8 @@ func FreeLibrary(handle Handle) (errno int) {
return return
} }
func GetProcAddress(module Handle, procname string) (proc Handle, errno int) { func GetProcAddress(module Handle, procname string) (proc uintptr, errno int) {
r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0) proc, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
proc = Handle(r0)
if proc == 0 { if proc == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
......
...@@ -141,9 +141,8 @@ func FreeLibrary(handle Handle) (errno int) { ...@@ -141,9 +141,8 @@ func FreeLibrary(handle Handle) (errno int) {
return return
} }
func GetProcAddress(module Handle, procname string) (proc Handle, errno int) { func GetProcAddress(module Handle, procname string) (proc uintptr, errno int) {
r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0) proc, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
proc = Handle(r0)
if proc == 0 { if proc == 0 {
if e1 != 0 { if e1 != 0 {
errno = int(e1) errno = int(e1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment