1// +build windows
2
3package ole
4
5import (
6	"fmt"
7	"syscall"
8	"unicode/utf16"
9)
10
11// errstr converts error code to string.
12func errstr(errno int) string {
13	// ask windows for the remaining errors
14	var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
15	b := make([]uint16, 300)
16	n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
17	if err != nil {
18		return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
19	}
20	// trim terminating \r and \n
21	for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
22	}
23	return string(utf16.Decode(b[:n]))
24}
25