2015. 9. 11. 15:00 윈도우/참고

CString getMyLastErrorMsg(CString strFunction)
{
    LPVOID lpMsgBuf;
    DWORD dw = GetLastError();

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER |
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

 CString strMsg;
 strMsg.Format(_T("%s failed with error %d: %s"), strFunction, dw, (LPCTSTR)lpMsgBuf);

    LocalFree(lpMsgBuf);

 return strMsg;
}

posted by townone