Sine Striker
2023-12-01 027122452a25191b81fef8fe35f5b54768d435f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "qwindowkit_windows.h"
 
namespace QWK {
 
    QString winErrorMessage(DWORD code) {
        LPWSTR buf = nullptr;
        if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
                                 FORMAT_MESSAGE_IGNORE_INSERTS,
                             nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                             reinterpret_cast<LPWSTR>(&buf), 0, nullptr) == 0) {
            return {};
        }
        const QString &errorText = QString::fromWCharArray(buf).trimmed();
        ::LocalFree(buf);
        return errorText;
    }
 
    QString winLastErrorMessage() {
        return winErrorMessage(::GetLastError());
    }
 
}