Skip to content

nice stuff from DragoonX6 #16

@dndn1011

Description

@dndn1011

#include
#include
#include

#include <Windows.h>

std::string LastError()
{
LPWSTR buffer;

FormatMessageW(
    FORMAT_MESSAGE_ALLOCATE_BUFFER
    | FORMAT_MESSAGE_FROM_SYSTEM
    | FORMAT_MESSAGE_IGNORE_INSERTS,
    nullptr,
    GetLastError(),
    0,
    (LPWSTR)&buffer,
    0,
    nullptr);

int required = WideCharToMultiByte(
    CP_UTF8,
    0,
    buffer,
    -1,
    nullptr,
    0,
    nullptr,
    nullptr);

std::string output;
output.resize(required);

WideCharToMultiByte(
    CP_UTF8,
    0,
    buffer,
    -1,
    output.data(),
    output.size(),
    nullptr,
    nullptr);

LocalFree(buffer);

return output;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions