Skip to content

Commit 5f1a99a

Browse files
committed
delete Ptr, PtrToString, StringToPtr
1 parent 097985c commit 5f1a99a

File tree

3 files changed

+25
-111
lines changed

3 files changed

+25
-111
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ Anton Lahti <[email protected]>
1414
Benny Siegert <[email protected]>
1515
Cary Cherng <[email protected]>
1616
17+
1718
1819

user32.go

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,6 @@ type (
11861186
HRAWINPUT HANDLE
11871187
HWND HANDLE
11881188
LRESULT int
1189-
WPARAM uintptr
1190-
LPARAM uintptr
1191-
UINT uint32
11921189
)
11931190

11941191
type MSG struct {
@@ -1714,11 +1711,11 @@ func CloseClipboard() bool {
17141711
}
17151712

17161713
func CreateDialogParam(instRes HINSTANCE, name *uint16, parent HWND,
1717-
proc uintptr, param uintptr) HWND {
1714+
proc, param uintptr) HWND {
17181715
ret, _, _ := syscall.Syscall6(createDialogParam, 5,
1719-
Ptr(instRes),
1720-
Ptr(name),
1721-
Ptr(parent),
1716+
uintptr(instRes),
1717+
uintptr(unsafe.Pointer(name)),
1718+
uintptr(parent),
17221719
proc,
17231720
param,
17241721
0)
@@ -1825,11 +1822,11 @@ func DestroyWindow(hWnd HWND) bool {
18251822
return ret != 0
18261823
}
18271824

1828-
func DialogBoxParam(instRes HINSTANCE, name *uint16, parent HWND, proc uintptr, param uintptr) int {
1825+
func DialogBoxParam(instRes HINSTANCE, name *uint16, parent HWND, proc, param uintptr) int {
18291826
ret, _, _ := syscall.Syscall6(dialogBoxParam, 5,
1830-
Ptr(instRes),
1831-
Ptr(name),
1832-
Ptr(parent),
1827+
uintptr(instRes),
1828+
uintptr(unsafe.Pointer(name)),
1829+
uintptr(parent),
18331830
proc,
18341831
param,
18351832
0)
@@ -1905,8 +1902,8 @@ func EndDeferWindowPos(hWinPosInfo HDWP) bool {
19051902

19061903
func EndDialog(hwnd HWND, result int) bool {
19071904
ret, _, _ := syscall.Syscall(endDialog, 2,
1908-
Ptr(hwnd),
1909-
Ptr(result),
1905+
uintptr(hwnd),
1906+
uintptr(result),
19101907
0)
19111908

19121909
return ret != 0
@@ -2241,23 +2238,23 @@ func LoadImage(hinst HINSTANCE, lpszName *uint16, uType uint32, cxDesired, cyDes
22412238

22422239
func LoadMenu(hinst HINSTANCE, name *uint16) HMENU {
22432240
ret, _, _ := syscall.Syscall(loadMenu, 2,
2244-
Ptr(hinst),
2245-
Ptr(name),
2241+
uintptr(hinst),
2242+
uintptr(unsafe.Pointer(name)),
22462243
0)
22472244

22482245
return HMENU(ret)
22492246
}
22502247

2251-
func LoadString(instRes HINSTANCE, id uint, buf *uint16, length int) int {
2248+
func LoadString(instRes HINSTANCE, id uint32, buf *uint16, length int32) int32 {
22522249
ret, _, _ := syscall.Syscall6(loadString, 4,
2253-
Ptr(instRes),
2254-
Ptr(id),
2255-
Ptr(buf),
2256-
Ptr(length),
2250+
uintptr(instRes),
2251+
uintptr(id),
2252+
uintptr(unsafe.Pointer(buf)),
2253+
uintptr(length),
22572254
0,
22582255
0)
22592256

2260-
return int(ret)
2257+
return int32(ret)
22612258
}
22622259

22632260
func MessageBox(hWnd HWND, lpText, lpCaption *uint16, uType uint32) int32 {
@@ -2295,7 +2292,7 @@ func MoveWindow(hWnd HWND, x, y, width, height int32, repaint bool) bool {
22952292

22962293
func UnregisterClass(name *uint16) bool {
22972294
ret, _, _ := syscall.Syscall(unregisterClass, 1,
2298-
Ptr(name),
2295+
uintptr(unsafe.Pointer(name)),
22992296
0,
23002297
0)
23012298

@@ -2405,16 +2402,16 @@ func ScreenToClient(hWnd HWND, point *POINT) bool {
24052402
return ret != 0
24062403
}
24072404

2408-
func SendDlgItemMessage(hWnd HWND, id int, msg UINT, wParam WPARAM, lParam LPARAM) LRESULT {
2405+
func SendDlgItemMessage(hWnd HWND, id int32, msg uint32, wParam, lParam uintptr) uintptr {
24092406
ret, _, _ := syscall.Syscall6(sendDlgItemMessage, 5,
24102407
uintptr(hWnd),
24112408
uintptr(id),
24122409
uintptr(msg),
2413-
uintptr(wParam),
2414-
uintptr(lParam),
2410+
wParam,
2411+
lParam,
24152412
0)
24162413

2417-
return LRESULT(ret)
2414+
return ret
24182415
}
24192416

24202417
func SendInput(nInputs uint32, pInputs unsafe.Pointer, cbSize int32) uint32 {
@@ -2650,7 +2647,7 @@ func TranslateMessage(msg *MSG) bool {
26502647

26512648
func UpdateWindow(hwnd HWND) bool {
26522649
ret, _, _ := syscall.Syscall(updateWindow, 1,
2653-
Ptr(hwnd),
2650+
uintptr(hwnd),
26542651
0,
26552652
0)
26562653

winapi.go

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
package winapi
66

77
import (
8-
"reflect"
98
"runtime"
10-
"strconv"
119
"syscall"
12-
"unicode/utf16"
1310
"unsafe"
1411
)
1512

@@ -118,84 +115,3 @@ func BoolToBOOL(value bool) BOOL {
118115

119116
return 0
120117
}
121-
122-
func GoStringToPtr(v string) uintptr {
123-
if v == "" {
124-
return 0
125-
}
126-
127-
u := utf16.Encode([]rune(v))
128-
u = append(u, 0)
129-
130-
return uintptr(unsafe.Pointer(&u[0]))
131-
}
132-
133-
func PtrToGoString(v uintptr) string {
134-
if v == 0 {
135-
return ""
136-
}
137-
138-
vp := (*[1 << 29]uint16)(unsafe.Pointer(v))
139-
size := 0
140-
for ; vp[size] != 0; size++ {
141-
}
142-
143-
return string(utf16.Decode(vp[:size]))
144-
}
145-
146-
func Ptr(i interface{}) (ret uintptr) {
147-
v := reflect.ValueOf(i)
148-
switch v.Kind() {
149-
case reflect.Slice, reflect.Func, reflect.Ptr, reflect.UnsafePointer:
150-
ret = v.Pointer()
151-
break
152-
153-
case reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
154-
ret = uintptr(v.Uint())
155-
break
156-
157-
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
158-
ret = uintptr(v.Int())
159-
break
160-
161-
case reflect.String:
162-
ret = GoStringToPtr(v.String())
163-
break
164-
165-
case reflect.Bool:
166-
if v.Bool() {
167-
ret = 1
168-
} else {
169-
ret = 0
170-
}
171-
break
172-
}
173-
174-
return
175-
}
176-
177-
func allNumber(s string) bool {
178-
for _, v := range s {
179-
if !(v >= '0' && v <= '9') {
180-
return false
181-
}
182-
}
183-
184-
return true
185-
}
186-
187-
func ResourceNameToUTF16Ptr(name string) (id *uint16) {
188-
number := allNumber(name)
189-
if number {
190-
idNumber, err := strconv.Atoi(name)
191-
if err != nil {
192-
id = syscall.StringToUTF16Ptr(name)
193-
} else {
194-
id = MAKEINTRESOURCE(uintptr(idNumber))
195-
}
196-
} else {
197-
id = syscall.StringToUTF16Ptr(name)
198-
}
199-
200-
return
201-
}

0 commit comments

Comments
 (0)