-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.go
78 lines (66 loc) · 1.32 KB
/
funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// +build windows
// miniblink及wke头文件导入
// 由ying32翻译,应用于govcl
package miniblink
import (
"syscall"
"unsafe"
"github.com/ying32/govcl/vcl/win"
)
func GoBool(val uintptr) bool {
if val != 0 {
return true
}
return false
}
func CBool(val bool) uintptr {
if val {
return 1
}
return 0
}
func GoWStr(str uintptr) string {
if str == 0 {
return ""
}
l := win.LstrlenW(str)
if l == 0 {
return ""
}
buff := make([]uint16, l)
win.Memcpy(uintptr(unsafe.Pointer(&buff[0])), str, uintptr(l*2))
return syscall.UTF16ToString(buff)
}
func GoAStr(str uintptr) string {
if str == 0 {
return ""
}
l := win.Lstrlen(str)
if l == 0 {
return ""
}
buff := make([]byte, l)
win.Memcpy(uintptr(unsafe.Pointer(&buff[0])), str, uintptr(l))
return string(buff)
}
func CWStr(str string) uintptr {
if str == "" {
return 0
}
return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
}
func CAStr(str string) uintptr {
if str == "" {
return 0
}
return uintptr(unsafe.Pointer(&([]byte(str + "\x00"))[0]))
}
// 下面两个函数主要是给 386平台使用的,amd64不需要使用
func ToUInt64(r1, r2 uintptr) uint64 {
ret := uint64(r2)
ret = uint64(ret<<32) + uint64(r1)
return ret
}
func UInt64To(val uint64) (uintptr, uintptr) {
return uintptr(uint32(val)), uintptr(uint32(val >> 32))
}