os.Exit(1)
}
-func abortErrNo(funcname string, err int) {
- abortf("%s failed: %d %s\n", funcname, err, syscall.Errstr(err))
+func abortErrNo(funcname string, err error) {
+ errno, _ := err.(syscall.Errno)
+ abortf("%s failed: %d %s\n", funcname, uint32(errno), err)
}
// global vars
func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
switch msg {
case WM_CREATE:
- var e int
+ var e error
// CreateWindowEx
bh, e = CreateWindowEx(
0,
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
75, 70, 140, 25,
hwnd, 1, mh, 0)
- if e != 0 {
+ if e != nil {
abortErrNo("CreateWindowEx", e)
}
fmt.Printf("button handle is %x\n", bh)
switch syscall.Handle(lparam) {
case bh:
e := PostMessage(hwnd, WM_CLOSE, 0, 0)
- if e != 0 {
+ if e != nil {
abortErrNo("PostMessage", e)
}
default:
}
func rungui() int {
- var e int
+ var e error
// GetModuleHandle
mh, e = GetModuleHandle(nil)
- if e != 0 {
+ if e != nil {
abortErrNo("GetModuleHandle", e)
}
// Get icon we're going to use.
myicon, e := LoadIcon(0, IDI_APPLICATION)
- if e != 0 {
+ if e != nil {
abortErrNo("LoadIcon", e)
}
// Get cursor we're going to use.
mycursor, e := LoadCursor(0, IDC_ARROW)
- if e != 0 {
+ if e != nil {
abortErrNo("LoadCursor", e)
}
wc.MenuName = nil
wc.ClassName = wcname
wc.IconSm = myicon
- if _, e := RegisterClassEx(&wc); e != 0 {
+ if _, e := RegisterClassEx(&wc); e != nil {
abortErrNo("RegisterClassEx", e)
}
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
0, 0, mh, 0)
- if e != 0 {
+ if e != nil {
abortErrNo("CreateWindowEx", e)
}
fmt.Printf("main window handle is %x\n", wh)
ShowWindow(wh, SW_SHOWDEFAULT)
// UpdateWindow
- if e := UpdateWindow(wh); e != 0 {
+ if e := UpdateWindow(wh); e != nil {
abortErrNo("UpdateWindow", e)
}
var m Msg
for {
r, e := GetMessage(&m, 0, 0, 0)
- if e != 0 {
+ if e != nil {
abortErrNo("GetMessage", e)
}
if r == 0 {
IDI_INFORMATION = IDI_ASTERISK
)
-//sys GetModuleHandle(modname *uint16) (handle syscall.Handle, errno int) = GetModuleHandleW
-//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 syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, errno int) = user32.CreateWindowExW
+//sys GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) = GetModuleHandleW
+//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, err error) = user32.RegisterClassExW
+//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, err error) = user32.CreateWindowExW
//sys DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.DefWindowProcW
-//sys DestroyWindow(hwnd syscall.Handle) (errno int) = user32.DestroyWindow
+//sys DestroyWindow(hwnd syscall.Handle) (err error) = user32.DestroyWindow
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
//sys ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) = user32.ShowWindow
-//sys UpdateWindow(hwnd syscall.Handle) (errno int) = user32.UpdateWindow
-//sys GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
+//sys UpdateWindow(hwnd syscall.Handle) (err error) = user32.UpdateWindow
+//sys GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) [failretval==-1] = user32.GetMessageW
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
-//sys LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, errno int) = user32.LoadIconW
-//sys LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, errno int) = user32.LoadCursorW
-//sys SetCursor(cursor syscall.Handle) (precursor syscall.Handle, errno int) = user32.SetCursor
+//sys LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, err error) = user32.LoadIconW
+//sys LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, err error) = user32.LoadCursorW
+//sys SetCursor(cursor syscall.Handle) (precursor syscall.Handle, err error) = user32.SetCursor
//sys SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.SendMessageW
-//sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (errno int) = user32.PostMessageW
+//sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) = user32.PostMessageW
func MakeIntResource(id uint16) *uint16 {
return (*uint16)(unsafe.Pointer(uintptr(id)))
procPostMessageW = moduser32.NewProc("PostMessageW")
)
-func GetModuleHandle(modname *uint16) (handle syscall.Handle, errno int) {
+func GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0)
handle = syscall.Handle(r0)
if handle == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
-func RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) {
+func RegisterClassEx(wndclass *Wndclassex) (atom uint16, err error) {
r0, _, e1 := syscall.Syscall(procRegisterClassExW.Addr(), 1, uintptr(unsafe.Pointer(wndclass)), 0, 0)
atom = uint16(r0)
if atom == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
-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) {
+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, err error) {
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 = syscall.Handle(r0)
if hwnd == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
return
}
-func DestroyWindow(hwnd syscall.Handle) (errno int) {
+func DestroyWindow(hwnd syscall.Handle) (err error) {
r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
return
}
-func UpdateWindow(hwnd syscall.Handle) (errno int) {
+func UpdateWindow(hwnd syscall.Handle) (err error) {
r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
-func GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) {
+func GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
ret = int32(r0)
if ret == -1 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
return
}
-func LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, errno int) {
+func LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procLoadIconW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0)
icon = syscall.Handle(r0)
if icon == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
-func LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, errno int) {
+func LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procLoadCursorW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0)
cursor = syscall.Handle(r0)
if cursor == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
-func SetCursor(cursor syscall.Handle) (precursor syscall.Handle, errno int) {
+func SetCursor(cursor syscall.Handle) (precursor syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0)
precursor = syscall.Handle(r0)
if precursor == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
return
}
-func PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (errno int) {
+func PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) {
r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
- errno = int(e1)
+ err = error(e1)
} else {
- errno = syscall.EINVAL
+ err = syscall.EINVAL
}
- } else {
- errno = 0
}
return
}
func initMime() {
var root syscall.Handle
if syscall.RegOpenKeyEx(syscall.HKEY_CLASSES_ROOT, syscall.StringToUTF16Ptr(`\`),
- 0, syscall.KEY_READ, &root) != 0 {
+ 0, syscall.KEY_READ, &root) != nil {
return
}
defer syscall.RegCloseKey(root)
var count uint32
- if syscall.RegQueryInfoKey(root, nil, nil, nil, &count, nil, nil, nil, nil, nil, nil, nil) != 0 {
+ if syscall.RegQueryInfoKey(root, nil, nil, nil, &count, nil, nil, nil, nil, nil, nil, nil) != nil {
return
}
var buf [1 << 10]uint16
for i := uint32(0); i < count; i++ {
n := uint32(len(buf))
- if syscall.RegEnumKeyEx(root, i, &buf[0], &n, nil, nil, nil, nil) != 0 {
+ if syscall.RegEnumKeyEx(root, i, &buf[0], &n, nil, nil, nil, nil) != nil {
continue
}
ext := syscall.UTF16ToString(buf[:])
var h syscall.Handle
if syscall.RegOpenKeyEx(
syscall.HKEY_CLASSES_ROOT, syscall.StringToUTF16Ptr(`\`+ext),
- 0, syscall.KEY_READ, &h) != 0 {
+ 0, syscall.KEY_READ, &h) != nil {
continue
}
var typ uint32
n = uint32(len(buf) * 2) // api expects array of bytes, not uint16
if syscall.RegQueryValueEx(
h, syscall.StringToUTF16Ptr("Content Type"),
- nil, &typ, (*byte)(unsafe.Pointer(&buf[0])), &n) != 0 {
+ nil, &typ, (*byte)(unsafe.Pointer(&buf[0])), &n) != nil {
syscall.RegCloseKey(h)
continue
}
func init() {
var d syscall.WSAData
e := syscall.WSAStartup(uint32(0x202), &d)
- if e != 0 {
- initErr = os.NewSyscallError("WSAStartup", syscall.Errno(e))
+ if e != nil {
+ initErr = os.NewSyscallError("WSAStartup", e)
}
}
a = (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
e = syscall.GetAdaptersInfo(a, &l)
}
- if e != 0 {
+ if e != nil {
return nil, os.NewSyscallError("GetAdaptersInfo", e)
}
return a, nil
row := syscall.MibIfRow{Index: index}
e := syscall.GetIfEntry(&row)
- if e != 0 {
+ if e != nil {
return nil, os.NewSyscallError("GetIfEntry", e)
}
func LookupCNAME(name string) (cname string, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(name, syscall.DNS_TYPE_CNAME, 0, nil, &r, nil)
- if e != 0 {
+ if e != nil {
return "", os.NewSyscallError("LookupCNAME", e)
}
defer syscall.DnsRecordListFree(r, 1)
}
var r *syscall.DNSRecord
e := syscall.DnsQuery(target, syscall.DNS_TYPE_SRV, 0, nil, &r, nil)
- if e != 0 {
+ if e != nil {
return "", nil, os.NewSyscallError("LookupSRV", e)
}
defer syscall.DnsRecordListFree(r, 1)
func LookupMX(name string) (mx []*MX, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(name, syscall.DNS_TYPE_MX, 0, nil, &r, nil)
- if e != 0 {
+ if e != nil {
return nil, os.NewSyscallError("LookupMX", e)
}
defer syscall.DnsRecordListFree(r, 1)
func LookupTXT(name string) (txt []string, err error) {
var r *syscall.DNSRecord
e := syscall.DnsQuery(name, syscall.DNS_TYPE_TEXT, 0, nil, &r, nil)
- if e != 0 {
+ if e != nil {
return nil, os.NewSyscallError("LookupTXT", e)
}
defer syscall.DnsRecordListFree(r, 1)
}
var r *syscall.DNSRecord
e := syscall.DnsQuery(arpa, syscall.DNS_TYPE_PTR, 0, nil, &r, nil)
- if e != 0 {
+ if e != nil {
return nil, os.NewSyscallError("LookupAddr", e)
}
defer syscall.DnsRecordListFree(r, 1)
"sync"
)
-// Errno is the Windows error number.
-type Errno uintptr
-
-func (e Errno) Error() string {
- return errstr(e)
-}
-
-func (e Errno) Temporary() bool {
- return e == EINTR || e == EMFILE || e.Timeout()
-}
-
-func (e Errno) Timeout() bool {
- return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
-}
-
// DLLError describes reasons for DLL load failures.
type DLLError struct {
Err error
$body .= "\t\t\t$name = ${syscalldot}EINVAL\n";
$body .= "\t\t}\n";
$body .= "\t}\n";
+ } elsif($rettype eq "error") {
+ # Set $reg to "error" only if returned value indicate failure
+ $body .= "\tif $reg != 0 {\n";
+ $body .= "\t\t$name = Errno($reg)\n";
+ $body .= "\t}\n";
} else {
$body .= "\t$name = $rettype($reg)\n";
}
func Getpagesize() int { return 4096 }
+// Errno is the Windows error number.
+type Errno uintptr
+
+func (e Errno) Error() string {
+ // deal with special go errors
+ idx := int(e - APPLICATION_ERROR)
+ if 0 <= idx && idx < len(errors) {
+ return errors[idx]
+ }
+ // ask windows for the remaining errors
+ var flags uint32 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS
+ b := make([]uint16, 300)
+ n, err := FormatMessage(flags, 0, uint32(e), 0, b, nil)
+ if err != nil {
+ return "error " + itoa(int(e)) + " (FormatMessage failed with err=" + itoa(int(err.(Errno))) + ")"
+ }
+ // trim terminating \r and \n
+ for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
+ }
+ return string(utf16.Decode(b[:n]))
+}
+
+func (e Errno) Temporary() bool {
+ return e == EINTR || e == EMFILE || e.Timeout()
+}
+
+func (e Errno) Timeout() bool {
+ return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
+}
+
// Converts a Go function to a function pointer conforming
// to the stdcall calling convention. This is useful when
// interoperating with Windows code requiring callbacks.
// windows api calls
-//sys GetLastError() (lasterr uintptr)
+//sys GetLastError() (lasterr error)
//sys LoadLibrary(libname string) (handle Handle, err error) = LoadLibraryW
//sys FreeLibrary(handle Handle) (err error)
//sys GetProcAddress(module Handle, procname string) (proc uintptr, err error)
//sys CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) = crypt32.CertOpenSystemStoreW
//sys CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) [failretval==nil] = crypt32.CertEnumCertificatesInStore
//sys CertCloseStore(store Handle, flags uint32) (err error) = crypt32.CertCloseStore
-//sys RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno uintptr) = advapi32.RegOpenKeyExW
-//sys RegCloseKey(key Handle) (regerrno uintptr) = advapi32.RegCloseKey
-//sys RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno uintptr) = advapi32.RegQueryInfoKeyW
-//sys RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno uintptr) = advapi32.RegEnumKeyExW
-//sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno uintptr) = advapi32.RegQueryValueExW
+//sys RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) = advapi32.RegOpenKeyExW
+//sys RegCloseKey(key Handle) (regerrno error) = advapi32.RegCloseKey
+//sys RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegQueryInfoKeyW
+//sys RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegEnumKeyExW
+//sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegQueryValueExW
// syscall interface implementation for other packages
-
-func errstr(errno Errno) string {
- // deal with special go errors
- e := int(errno - APPLICATION_ERROR)
- if 0 <= e && e < len(errors) {
- return errors[e]
- }
- // ask windows for the remaining errors
- var flags uint32 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS
- b := make([]uint16, 300)
- n, err := FormatMessage(flags, 0, uint32(errno), 0, b, nil)
- if err != nil {
- return "error " + itoa(int(errno)) + " (FormatMessage failed with err=" + itoa(int(err.(Errno))) + ")"
- }
- // trim terminating \r and \n
- for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
- }
- return string(utf16.Decode(b[:n]))
-}
-
func Exit(code int) { ExitProcess(uint32(code)) }
func makeInheritSa() *SecurityAttributes {
// net api calls
-//sys WSAStartup(verreq uint32, data *WSAData) (sockerr uintptr) = ws2_32.WSAStartup
+//sys WSAStartup(verreq uint32, data *WSAData) (sockerr error) = ws2_32.WSAStartup
//sys WSACleanup() (err error) [failretval==-1] = ws2_32.WSACleanup
//sys WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) [failretval==-1] = ws2_32.WSAIoctl
//sys socket(af int32, typ int32, protocol int32) (handle Handle, err error) [failretval==InvalidHandle] = ws2_32.socket
//sys GetServByName(name string, proto string) (s *Servent, err error) [failretval==nil] = ws2_32.getservbyname
//sys Ntohs(netshort uint16) (u uint16) = ws2_32.ntohs
//sys GetProtoByName(name string) (p *Protoent, err error) [failretval==nil] = ws2_32.getprotobyname
-//sys DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status Errno) = dnsapi.DnsQuery_W
+//sys DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) = dnsapi.DnsQuery_W
//sys DnsRecordListFree(rl *DNSRecord, freetype uint32) = dnsapi.DnsRecordListFree
-//sys GetIfEntry(pIfRow *MibIfRow) (errcode Errno) = iphlpapi.GetIfEntry
-//sys GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode Errno) = iphlpapi.GetAdaptersInfo
+//sys GetIfEntry(pIfRow *MibIfRow) (errcode error) = iphlpapi.GetIfEntry
+//sys GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) = iphlpapi.GetAdaptersInfo
// For testing: clients can set this flag to force
// creation of IPv6 sockets to return EAFNOSUPPORT.
procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
)
-func GetLastError() (lasterr uintptr) {
+func GetLastError() (lasterr error) {
r0, _, _ := Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
- lasterr = uintptr(r0)
+ if r0 != 0 {
+ lasterr = Errno(r0)
+ }
return
}
return
}
-func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno uintptr) {
+func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
r0, _, _ := Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegCloseKey(key Handle) (regerrno uintptr) {
+func RegCloseKey(key Handle) (regerrno error) {
r0, _, _ := Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno uintptr) {
+func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno uintptr) {
+func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno uintptr) {
+func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
r0, _, _ := Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func WSAStartup(verreq uint32, data *WSAData) (sockerr uintptr) {
+func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
r0, _, _ := Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
- sockerr = uintptr(r0)
+ if r0 != 0 {
+ sockerr = Errno(r0)
+ }
return
}
return
}
-func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status Errno) {
+func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
r0, _, _ := Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(StringToUTF16Ptr(name))), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
- status = Errno(r0)
+ if r0 != 0 {
+ status = Errno(r0)
+ }
return
}
return
}
-func GetIfEntry(pIfRow *MibIfRow) (errcode Errno) {
+func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
r0, _, _ := Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
- errcode = Errno(r0)
+ if r0 != 0 {
+ errcode = Errno(r0)
+ }
return
}
-func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode Errno) {
+func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
r0, _, _ := Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
- errcode = Errno(r0)
+ if r0 != 0 {
+ errcode = Errno(r0)
+ }
return
}
procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
)
-func GetLastError() (lasterr uintptr) {
+func GetLastError() (lasterr error) {
r0, _, _ := Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
- lasterr = uintptr(r0)
+ if r0 != 0 {
+ lasterr = Errno(r0)
+ }
return
}
return
}
-func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno uintptr) {
+func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
r0, _, _ := Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegCloseKey(key Handle) (regerrno uintptr) {
+func RegCloseKey(key Handle) (regerrno error) {
r0, _, _ := Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno uintptr) {
+func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno uintptr) {
+func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
r0, _, _ := Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno uintptr) {
+func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
r0, _, _ := Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
- regerrno = uintptr(r0)
+ if r0 != 0 {
+ regerrno = Errno(r0)
+ }
return
}
-func WSAStartup(verreq uint32, data *WSAData) (sockerr uintptr) {
+func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
r0, _, _ := Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
- sockerr = uintptr(r0)
+ if r0 != 0 {
+ sockerr = Errno(r0)
+ }
return
}
return
}
-func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status Errno) {
+func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
r0, _, _ := Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(StringToUTF16Ptr(name))), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
- status = Errno(r0)
+ if r0 != 0 {
+ status = Errno(r0)
+ }
return
}
return
}
-func GetIfEntry(pIfRow *MibIfRow) (errcode Errno) {
+func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
r0, _, _ := Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
- errcode = Errno(r0)
+ if r0 != 0 {
+ errcode = Errno(r0)
+ }
return
}
-func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode Errno) {
+func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
r0, _, _ := Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
- errcode = Errno(r0)
+ if r0 != 0 {
+ errcode = Errno(r0)
+ }
return
}