Windows:
Use GetLastError () to obtain the error code, and use the FormatMessage API to obtain the error information corresponding to the error code,
HLOCAL pBuffer = NULL; // system buffer pointer
Int nId = GetDlgItemInt (IDC_EDIT1); // error code
: FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, nId, MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), reinterpret_cast <LPTSTR> (& pBuffer), 0, NULL );
// MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US) sets the output language of the error message to English.
// Reinterpret_cast tells the compiler to treat the type to be converted as the target type (the conversion is not actually executed)
SetDlgItemText (IDC_REDIT, static_cast <LPTSTR> (: LocalLock (pBuffer )));
: LocalFree (pBuffer); // release the system buffer.
In Linux:
# Include <errno. h>
Use errno error codes and use strerror (errno) to obtain error information corresponding to the error codes.
Reference http://blog.kingsamchen.com/archives/569