GetLastError() 함수로 얻은 에러 코드를 에러 문자열로 변환해 주는 함수다.
std::tstring GetErrorMessage(int ec)
{
LPVOID lpMsgBuf = 0;
DWORD retval = ::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ec,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
if (retval == 0)
return std::string(_T("Unknown error"));
return std::tstring(static_cast<LPCTSTR>(lpMsgBuf));
}
이런 함수를 만들어 놓으면 편하다.
'프로그래밍' 카테고리의 다른 글
| TCP 상태 변화 (TCP States) (0) | 2013.04.01 |
|---|---|
| gtest 사용하기 (0) | 2012.12.06 |
| include 가드 (0) | 2012.12.05 |
| Unicode 사용 (0) | 2012.12.05 |
| #define WIN32_LEAN_AND_MEAN (0) | 2012.12.05 |