38 lines
650 B
Go
38 lines
650 B
Go
//go:build windows
|
|
|
|
package app
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func decodeWithCodePage(b []byte, codePage uint32) string {
|
|
if len(b) == 0 {
|
|
return ""
|
|
}
|
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
|
multiByteToWideChar := kernel32.NewProc("MultiByteToWideChar")
|
|
n, _, _ := multiByteToWideChar.Call(
|
|
uintptr(codePage),
|
|
0,
|
|
uintptr(unsafe.Pointer(&b[0])),
|
|
uintptr(len(b)),
|
|
0,
|
|
0,
|
|
)
|
|
if n == 0 {
|
|
return ""
|
|
}
|
|
buf := make([]uint16, n)
|
|
multiByteToWideChar.Call(
|
|
uintptr(codePage),
|
|
0,
|
|
uintptr(unsafe.Pointer(&b[0])),
|
|
uintptr(len(b)),
|
|
uintptr(unsafe.Pointer(&buf[0])),
|
|
uintptr(len(buf)),
|
|
)
|
|
return utf16ToString(buf)
|
|
}
|