Вот пример использования FormatMessage ()
LPTSTR SRUTIL_WinErrorMsg(int nErrorCode, LPTSTR pStr, WORD wLength )
{
try
{
LPTSTR szBuffer = pStr;
int nBufferSize = wLength;
//
// prime buffer with error code
//
wsprintf( szBuffer, _T("Error code %u"), nErrorCode);
//
// if we have a message, replace default with msg.
//
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, nErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) szBuffer,
nBufferSize,
NULL );
}
catch(...)
{
}
return pStr;
} // End of SRUTIL_WinErrorMsg()