Files
Win2Linux/pkg/windows/windows.go
2026-04-19 12:56:16 +02:00

37 lines
710 B
Go

package windows
import (
"os"
"syscall"
"unsafe"
)
const (
NULL = 0
MB_OK = 0
)
func Fatal(title, message string, exitCode int) {
messageBox(NULL, message, title, MB_OK)
os.Exit(exitCode)
}
// MessageBox of Win32 API.
func messageBox(hwnd uintptr, caption, title string, flags uint) int {
_caption, err := syscall.UTF16PtrFromString(caption)
if err != nil {
panic(err)
}
_title, err := syscall.UTF16PtrFromString(title)
if err != nil {
panic(err)
}
ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(_caption)),
uintptr(unsafe.Pointer(_title)),
uintptr(flags))
return int(ret)
}