mirror of
https://github.com/golang/sys.git
synced 2026-02-08 19:56:04 +03:00
x/sys/windows: correct FormatMessage parameter
Second FormatMessage parameter lpSource is uintptr not uint32. Update golang/go#11147. Change-Id: Icaa67abaed93efdad41564b21f8e511e8f9694b1 Reviewed-on: https://go-review.googlesource.com/11165 Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
@@ -87,7 +87,7 @@ func NewCallbackCDecl(fn interface{}) uintptr
|
||||
//sys FreeLibrary(handle Handle) (err error)
|
||||
//sys GetProcAddress(module Handle, procname string) (proc uintptr, err error)
|
||||
//sys GetVersion() (ver uint32, err error)
|
||||
//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
|
||||
//sys FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
|
||||
//sys ExitProcess(exitcode uint32)
|
||||
//sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW
|
||||
//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
@@ -52,6 +53,38 @@ func TestWin32finddata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatMessage(t *testing.T) {
|
||||
dll := windows.MustLoadDLL("pdh.dll")
|
||||
|
||||
pdhOpenQuery := func(datasrc *uint16, userdata uint32, query *windows.Handle) (errno uintptr) {
|
||||
r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhOpenQueryW").Addr(), 3, uintptr(unsafe.Pointer(datasrc)), uintptr(userdata), uintptr(unsafe.Pointer(query)))
|
||||
return r0
|
||||
}
|
||||
|
||||
pdhCloseQuery := func(query windows.Handle) (errno uintptr) {
|
||||
r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhCloseQuery").Addr(), 1, uintptr(query), 0, 0)
|
||||
return r0
|
||||
}
|
||||
|
||||
var q windows.Handle
|
||||
name, err := windows.UTF16PtrFromString("no_such_source")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
errno := pdhOpenQuery(name, 0, &q)
|
||||
if errno == 0 {
|
||||
pdhCloseQuery(q)
|
||||
t.Fatal("PdhOpenQuery succeeded, but expected to fail.")
|
||||
}
|
||||
|
||||
const flags uint32 = syscall.FORMAT_MESSAGE_FROM_HMODULE | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
|
||||
buf := make([]uint16, 300)
|
||||
_, err = windows.FormatMessage(flags, uintptr(dll.Handle), uint32(errno), 0, buf, nil)
|
||||
if err != nil {
|
||||
t.Fatal("FormatMessage for handle=%x and errno=%x failed: %v", dll.Handle, errno, err)
|
||||
}
|
||||
}
|
||||
|
||||
func abort(funcname string, err error) {
|
||||
panic(funcname + " failed: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -473,7 +473,7 @@ func GetVersion() (ver uint32, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
|
||||
func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
|
||||
var _p0 *uint16
|
||||
if len(buf) > 0 {
|
||||
_p0 = &buf[0]
|
||||
|
||||
Reference in New Issue
Block a user