예제 #1
0
func (hr HResult) Error() string {
	buf := make([]uint16, 300)
	n, err := syscall.FormatMessage(syscall.FORMAT_MESSAGE_FROM_SYSTEM|syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY|syscall.FORMAT_MESSAGE_IGNORE_INSERTS,
		0, uint32(hr), 0, buf, nil)
	if err != nil {
		return fmt.Sprintf("COM error %08x", uint32(hr))
	}
	return strings.TrimSpace(string(utf16.Decode(buf[:n])))
}
예제 #2
0
func (hr hresult) Error() string {
	i := uint32(hr)
	if 1 < i {
		flags := uint32(syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS)
		b := make([]uint16, 300)
		if _, err := syscall.FormatMessage(flags, 0, i, 0, b, nil); err == nil {
			return strings.TrimSpace(syscall.UTF16ToString(b))
		}
	}
	return fmt.Sprintf("0x%08x", i)
}
예제 #3
0
func errstr(errno int) string {
	// ask windows for the remaining errors
	var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
	b := make([]uint16, 300)
	n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
	if err != nil {
		return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
	}
	// trim terminating \r and \n
	for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
	}
	return string(utf16.Decode(b[:n]))
}
예제 #4
0
func (hr HResult) String() string {

	var name string

	switch hr {
	case S_OK:
		name = "S_OK"
	case S_FALSE:
		name = "S_FALSE"
	case E_NOTIMPL:
		name = "E_NOTIMPL"
	case E_NOINTERFACE:
		name = "E_NOINTERFACE"
	case E_POINTER:
		name = "E_POINTER"
	case CO_E_NOTINITIALIZED:
		name = "CO_E_NOTINITIALIZED"
	default:
		name = fmt.Sprintf("0x%08X", uint32(hr))
	}

	var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
	buf := make([]uint16, 320)
	n, err := syscall.FormatMessage(flags, 0, uint32(hr), 0, buf, nil)
	if n > 0 && err == nil {

		// trim trailing newline
		for n > 0 && (buf[n-1] == '\n' || buf[n-1] == '\r') {
			n--
		}

		msg := string(utf16.Decode(buf[:n]))
		return fmt.Sprintf("%s: %s", name, msg)
	}

	return name
}