Azure/C++/C#/Java/Asp.net/JavaScript/Html - MFC/COM/ActiveX/eclipse/Web

dlbrant

working soft

博客园 首页 新随笔 管理

 

CString CXXUtil::FormatMessageFor(HRESULT hr)
{
    CString strMsg;
    LPVOID pvMsgBuf = NULL;
    LPCTSTR pszMsg = NULL;
    if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL, (DWORD)hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &pvMsgBuf, 0, NULL ))
    {
        pszMsg = (LPTSTR)pvMsgBuf;
        // Do something with the error message.
        //printf( "Windows error: 0X%.8X (%s)\n", a_hResult, a_pszMsg );
        strMsg.Format(_T("0X%.8X (%s)"), hr, pszMsg);
        LocalFree(pvMsgBuf);
    }
    return strMsg;
}
View Code

 

posted on 2013-07-09 14:46  dlbrant  阅读(714)  评论(0编辑  收藏  举报

Software