Skip to content

x/sys/windows: error codes for HRESULTs should be int32, not Handle #48736

@dblohm7

Description

@dblohm7

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

$ go version
go version go1.17.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/$USER/.cache/go-build"
GOENV="/home/$USER/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/$USER/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/$USER/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/$USER/src/tailscale/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build84692255=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Tried to check the return code of a Windows syscall, known to be an HRESULT.

What did you expect to see?

I expect to be able to do things that I can typically do with HRESULTs in C++, like check if they are negative (equivalent to the Windows SDK's FAILED macro), or compare my hresult value to a known HRESULT error code without the compiler complaining about type mismatches.

In Microsoft's Windows SDK for C and C++, HRESULTs are typedef'd as LONG, which on Windows is always an int32. Further details as to why HRESULTs are not actually handles are outlined by Raymond Chen on his blog.

What did you see instead?

Compile errors due to type mismatches, because error codes for HRESULTs are defined as having type Handle, which in turn is defined as uintptr. Error codes for HRESULTs should be int32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.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