示例#1
0
func (self COMError) Error() string {
	var message *uint16
	_, err := wrappers.FormatMessage(
		wrappers.FORMAT_MESSAGE_ALLOCATE_BUFFER|wrappers.FORMAT_MESSAGE_IGNORE_INSERTS|wrappers.FORMAT_MESSAGE_FROM_SYSTEM,
		0,
		uint32(self),
		0,
		(*uint16)(unsafe.Pointer(&message)),
		65536,
		nil)
	if err != nil {
		return fmt.Sprintf("com error 0x%08X", uint32(self))
	}
	defer wrappers.LocalFree(syscall.Handle(unsafe.Pointer(message)))
	return strings.TrimRight(LpstrToString(message), "\r\n")
}
示例#2
0
func (self NTError) Error() string {
	hModule, err := wrappers.LoadLibrary(syscall.StringToUTF16Ptr("ntdll.dll"))
	if err != nil {
		return fmt.Sprintf("nt error 0x%08X", uint32(self))
	}
	defer wrappers.FreeLibrary(hModule)
	var message *uint16
	_, err = wrappers.FormatMessage(
		wrappers.FORMAT_MESSAGE_ALLOCATE_BUFFER|wrappers.FORMAT_MESSAGE_FROM_SYSTEM|wrappers.FORMAT_MESSAGE_FROM_HMODULE,
		uintptr(hModule),
		uint32(self),
		0,
		(*uint16)(unsafe.Pointer(&message)),
		0,
		nil)
	if err != nil {
		return fmt.Sprintf("nt error 0x%08X", uint32(self))
	}
	defer wrappers.LocalFree(syscall.Handle(unsafe.Pointer(message)))
	return strings.TrimRight(LpstrToString(message), "\r\n")
}