dwError = GetLastError();
HLOCAL hlocal = NULL;
//Get the error code's textual description
BOOL fOk = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(PTSTR)&hlocal, 0, NULL);
if (hlocal != NULL)
{
AfxMessageBox( (PCTSTR)LocalLock(hlocal));
LocalFree(hlocal);
}
else
AfxMessageBox(("Error number not found."));