Sine Striker
2023-12-06 a0bede6ff6a700a6eea9702c49d378f07de22f63
src/core/qwindowkit_windows.cpp
@@ -1,22 +1 @@
#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());
    }
}