#include "pch.h"
#include "CWinErr.h"
#include <windows.h>
#include "aLog.h"


wchar_t* getWinErrString(DWORD winErrCode)
{
    wchar_t* lpMsgBuf = nullptr;

    auto nRet = FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
        nullptr,
        winErrCode,
        MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
        (LPTSTR)&lpMsgBuf,
        0, nullptr);
    if(nRet ==0) {
        LocalFree(lpMsgBuf);
        lpMsgBuf = nullptr;
    }
    return lpMsgBuf;
}

DWORD getWinErrString(DWORD winErrCode, wchar_t* lpMsgBuf, DWORD   nSize)
{
    return FormatMessage(
        FORMAT_MESSAGE_FROM_SYSTEM,
        nullptr,
        winErrCode,
        MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
        lpMsgBuf,
        nSize, nullptr);
    
}
