Add Device.getLastErrorMessage()

This commit is contained in:
Nodir Temirkhodjaev 2017-09-03 22:50:15 +05:00
parent 350f7837f0
commit 0e4c740859
2 changed files with 21 additions and 0 deletions

View File

@ -56,3 +56,22 @@ bool Device::ioctl(int code, char *in, int inSize,
return res; return res;
} }
QString Device::getLastErrorMessage()
{
const DWORD err = GetLastError();
LPWSTR buf = nullptr;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, 0, (LPWSTR) &buf, 0, NULL);
if (!buf) {
return QString("System Error %1").arg(err);
}
const QString text = QString::fromUtf16((const ushort *) buf).trimmed();
LocalFree(buf);
return text;
}

View File

@ -11,6 +11,8 @@ public:
explicit Device(QObject *parent = nullptr); explicit Device(QObject *parent = nullptr);
virtual ~Device(); virtual ~Device();
static QString getLastErrorMessage();
signals: signals:
public slots: public slots: