#include <stdio.h>
#include <Windows.h>
void fmtMsg()
{
LPTSTR errorText = NULL;
FormatMessage(
// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
| FORMAT_MESSAGE_ALLOCATE_BUFFER
// Important! will fail otherwise, since we're not
// (and CANNOT) pass insertion parameters
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&errorText, // output
0, // minimum size for output buffer
NULL);
if (errorText != NULL)
{
printf_s("%s", errorText);
// release memory allocated by FormatMessage()
LocalFree(errorText);
errorText = NULL;
}
}
int main()
{
fmtMsg();
return 0;
}
使用 FormatMessage 将 GetLastError 返回值转换为文字
最新推荐文章于 2022-12-17 15:42:57 发布