Archived
1
0
This repository has been archived on 2024-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
projfs/strings.go
2024-10-01 13:37:31 +00:00

31 lines
537 B
Go

//go:build windows
package projfs
import (
"syscall"
"unsafe"
)
func GetPointer(str string) uintptr {
ptr, err := syscall.UTF16PtrFromString(str)
if err != nil {
return 0
}
return uintptr(unsafe.Pointer(ptr))
}
func GetString(str uintptr) string {
p := (*uint16)(unsafe.Pointer(str))
if p == nil {
return ""
}
end := unsafe.Pointer(p)
n := 0
for *(*uint16)(end) != 0 {
end = unsafe.Pointer(uintptr(end) + unsafe.Sizeof(*p))
n++
}
return syscall.UTF16ToString(unsafe.Slice(p, n))
}