Are you constantly switching to the error lookup program to view the system error code returned by the API? That's too inefficient!
Let the system generate an error message string with the current default encoding:
//////////////////////////////////////// /////////////////////////////////////
//
// In
// DWORD dwerror error code. The default value (0 xffffffff) indicates that the last error code of this thread is obtained directly.
//
// Out
// The error message string generated by the cstring System
//
Static cstring geterrormsg (DWORD dwerror = 0 xffffffff)
{
Dwerror = (dwerror = 0 xffffffff )? Getlasterror (): dwerror;
// Format message
Lpvoid lpmsgbuf;
Formatmessage (
Format_message_allocate_buffer |
Format_message_from_system |
Format_message_ignore_inserts,
Null, // module to get message from (null = System)
Dwerror,
0, // default language: makelangid (lang_neutral, sublang_default)
(Lptstr) & lpmsgbuf,
0,
Null
);
// Process any inserts in lpmsgbuf.
//...
// Get the string.
Cstring strmsg (lpctstr) lpmsgbuf );
// Free the buffer.
Localfree (lpmsgbuf );
Strmsg. trimright (_ T ("/R/N "));
Return strmsg;
}
//////////////////////////////////////// /////////////////////////////////////
//
// In
// DWORD dwerror error code. The default value (0 xffffffff) indicates that the last error code of this thread is obtained directly.
//
// Out
// The error message string generated by the cstring System and the decimal value of the error code
//
Static cstring geterrormsgandcode (DWORD dwerror = 0 xffffffff)
{
Dwerror = (dwerror = 0 xffffffff )? Getlasterror (): dwerror;
Cstring strmsg;
Strmsg. Format (_ T ("% s (% d)"), geterrormsg (dwerror), dwerror );
Return strmsg;
}