I have routinely used the method you mentioned plus one more if it is a OS error.
//-----------------------------------------------------------------------------
BSTR
SfaUtil::getErrorInfo()
{
// Use this for getting ESRI errors
BSTR bError( L"Undefined" );
IErrorInfoPtr ipError;
::GetErrorInfo( 0, &ipError );
if ( ipError != 0 ) {
ipError->GetDescription( &bError );
}
return bError;
}
//-----------------------------------------------------------------------------
void
SfaUtil::displayWinErr()
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
}