示例#1
0
func wstrToString(wstr *C.WCHAR) string {
	n := C.wcslen((*C.wchar_t)(unsafe.Pointer(wstr)))
	xbuf := &reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(wstr)),
		Len:  int(n + 1),
		Cap:  int(n + 1),
	}
	buf := (*[]uint16)(unsafe.Pointer(xbuf))
	return syscall.UTF16ToString(*buf)
}
示例#2
0
文件: cgo.go 项目: postfix/go-lib7zip
func getString(ws *C.wchar_t) string {
	length := int(C.wcslen(ws))
	var sl []C.wchar_t
	sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&sl)))
	sliceHeader.Cap = length
	sliceHeader.Len = length
	sliceHeader.Data = uintptr(unsafe.Pointer(ws))

	s := make([]uint16, length)
	for i := 0; i < length; i++ {
		s[i] = uint16(sl[i])
	}

	return _UTF16ToString(s)
}