错误码

// 01 错误处理.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <windows.h>
#include <Strsafe.h>

void ShowErrorInfo(LPCTSTR lpErrInfo,
    UINT unErrCode,
    UINT unLine = __LINE__) // 示意,不能这么用
{
    LPTSTR lpMsgBuf = nullptr;
    WCHAR  szMessage[128] = { 0 };
    WCHAR  szCaption[32] = { 0 };

    //能够将错误码转换为错误信息

    FormatMessage(0x1300, NULL, unErrCode,
        0x400, (LPTSTR)&lpMsgBuf, 64, NULL);

    StringCchPrintfW(szMessage, 128,
        L"Error_0x%08X:%s", unErrCode, lpMsgBuf);

    StringCchPrintfW(szCaption, 32,
        L"%s (Error Line:%05d)", lpErrInfo, unLine);

    MessageBox(NULL, szMessage, szCaption, MB_OK);
}
int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE hFile = CreateFile(NULL, 0, 0, 0, 0, 0, 0);
    if (hFile==INVALID_HANDLE_VALUE)
    {
        ShowErrorInfo(NULL, GetLastError());
    }
    return 0;
}
让数据变得更安全!
原文地址:https://www.cnblogs.com/Alyoyojie/p/5304592.html