使用 FormatMessage 格式化 Windows 错误码.md
作者:互联网
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage
#include <string>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif // !WIN32_LEAN_AND_MEAN
#include <Windows.h>
std::string str_win_err(int err)
{
LPSTR buf = nullptr;
FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr,
err,
0,
(LPSTR)&buf,
0,
nullptr
);
std::string msg;
if (buf) {
msg.assign(buf);
LocalFree(buf);
}
return msg;
}
标签:md,err,Windows,nullptr,错误码,WIN32,msg,buf,MEAN 来源: https://www.cnblogs.com/mkckr0/p/15845251.html