lxn / win

A Windows API wrapper package for the Go Programming Language
Other
1.19k stars 312 forks source link

Provide the method to retrieve why the system call has been failed. #108

Open bupjae opened 3 years ago

bupjae commented 3 years ago

Source code:

package main

import (
    "fmt"
    "github.com/lxn/win"
    "golang.org/x/sys/windows"
)

func main() {
    wrongName := windows.StringToUTF16Ptr("ADFADFASDFSDAFASFD")
    handle := win.GetModuleHandle(wrongName)
    if handle == 0 {
        fmt.Println(win.GetLastError()) // This always returns 0. See https://github.com/golang/go/issues/41220
    }
}

Expected result: Error code describing 'module not found' (ERROR_MOD_NOT_FOUND, 126)

Actual result: 0

According to https://github.com/golang/go/issues/41220 , windows.GetLastError always returns nil. As the same reason, win.GetLastError always returns 0.

As wrapper provided by this package doesn't handle err return value from syscall.Syscall, the client doesn't know why the function call was failed.