天天看點

在VC中使用FormatMessage擷取GetLastError錯誤資訊并顯示

編者:李國帥

背景:

函數:

void showErrMessage(int errNO)

{

    LPVOID     lpMsgBuffer;

    DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |

            FORMAT_MESSAGE_FROM_SYSTEM,

            NULL,

            errNO,//1001,//錯誤編号

            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

            reinterpret_cast<LPTSTR>(&lpMsgBuffer),

                       0,

            NULL);


    MessageBox(0, reinterpret_cast<LPTSTR>(lpMsgBuffer), "ERROR", MB_OK);

    LocalFree(lpMsgBuffer);

}      

繼續閱讀