@@ -10,7 +10,6 @@ import (
10
10
"path/filepath"
11
11
"syscall"
12
12
"testing"
13
- "unsafe"
14
13
15
14
"golang.org/x/sys/windows"
16
15
)
@@ -54,34 +53,14 @@ func TestWin32finddata(t *testing.T) {
54
53
}
55
54
56
55
func TestFormatMessage (t * testing.T ) {
57
- dll := windows .MustLoadDLL ("pdh.dll" )
58
-
59
- pdhOpenQuery := func (datasrc * uint16 , userdata uint32 , query * windows.Handle ) (errno uintptr ) {
60
- r0 , _ , _ := syscall .Syscall (dll .MustFindProc ("PdhOpenQueryW" ).Addr (), 3 , uintptr (unsafe .Pointer (datasrc )), uintptr (userdata ), uintptr (unsafe .Pointer (query )))
61
- return r0
62
- }
63
-
64
- pdhCloseQuery := func (query windows.Handle ) (errno uintptr ) {
65
- r0 , _ , _ := syscall .Syscall (dll .MustFindProc ("PdhCloseQuery" ).Addr (), 1 , uintptr (query ), 0 , 0 )
66
- return r0
67
- }
68
-
69
- var q windows.Handle
70
- name , err := windows .UTF16PtrFromString ("no_such_source" )
71
- if err != nil {
72
- t .Fatal (err )
73
- }
74
- errno := pdhOpenQuery (name , 0 , & q )
75
- if errno == 0 {
76
- pdhCloseQuery (q )
77
- t .Fatal ("PdhOpenQuery succeeded, but expected to fail." )
78
- }
56
+ dll := windows .MustLoadDLL ("netevent.dll" )
79
57
58
+ const TITLE_SC_MESSAGE_BOX uint32 = 0xC0001B75
80
59
const flags uint32 = syscall .FORMAT_MESSAGE_FROM_HMODULE | syscall .FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall .FORMAT_MESSAGE_IGNORE_INSERTS
81
60
buf := make ([]uint16 , 300 )
82
- _ , err = windows .FormatMessage (flags , uintptr (dll .Handle ), uint32 ( errno ) , 0 , buf , nil )
61
+ _ , err : = windows .FormatMessage (flags , uintptr (dll .Handle ), TITLE_SC_MESSAGE_BOX , 0 , buf , nil )
83
62
if err != nil {
84
- t .Fatalf ("FormatMessage for handle=%x and errno=%x failed: %v" , dll .Handle , errno , err )
63
+ t .Fatalf ("FormatMessage for handle=%x and errno=%x failed: %v" , dll .Handle , TITLE_SC_MESSAGE_BOX , err )
85
64
}
86
65
}
87
66
0 commit comments