Skip to content

x/sys/windows: GetLastError always returns nil #41220

Open
@bupjae

Description

@bupjae

What version of Go are you using (go version)?

$ go version
go version go1.14.7 windows/amd64

Does this issue reproduce with the latest release?

Not tried, but I'm pretty sure it will.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Bupjae\AppData\Local\go-build
set GOENV=C:\Users\Bupjae\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Bupjae\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Bupjae\AppData\Local\Temp\go-build843644218=/tmp/go-build -gno-record-gcc-switches

What did you do?

package main

import (
	"fmt"
	"golang.org/x/sys/windows"
)

func main() {
	var handle windows.Handle
	wrongName := windows.StringToUTF16Ptr("ADFADFASDFSDAFASFD")
	err := windows.GetModuleHandleEx(0, wrongName, &handle)
	if handle == 0 {
		fmt.Println(err)
		fmt.Println(windows.GetLastError())
	}
}

What did you expect to see?

Prints out error message describing 'module not found' twice.

What did you see instead?

The specified module could not be found.
<nil>

According to https://golang.org/src/runtime/sys_windows_amd64.s , before calling actual DLL routine (line 58), last error information is erased (line 22-23). This makes syscall.GetLastError (and windows.GetLastError) completely meaningless,

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.OS-Windowscompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions