프로그래밍/조각코드
Windows API GetLastError 코드를 문자열로 출력하기
ngcbbs
2012. 4. 4. 14:22
다음과 같은 코드를 통해서 확인할 수 있다.
void ErrorMessageBox(DWORD dwError)
{
LPVOID lpMsg = NULL;
DWORD dwFormat = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
DWORD dwLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
if (!FormatMessage(dwFormat, NULL, dwError, dwLanguage,
(LPTSTR)&lpMsg, 0, NULL))
{
return;
}
MessageBox(NULL, (LPCTSTR)lpMsg, L"Error", MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsg);
}