`
helpbs
  • 浏览: 1165205 次
文章分类
社区版块
存档分类
最新评论

utilities for printing out messages

 
阅读更多

#ifndef __Util_h__
#define __Util_h__
//
// Util.h
// - Shared utilities
//
namespace Util
{
void Trace(char* szLabel, const char* szText, HRESULT hr) ;

void ErrorMessage(HRESULT hr) ;
} ;

#endif // __Util_h__

#include <stdlib.h>
#include <iostream.h>
#include <assert.h>

#include "Util.h"

namespace Util
{
//
// Print out a message with a label.
//
void Trace(char* szLabel, const char* szText, HRESULT hr)
{
cout << szLabel
<< ": /t"
<< szText
<< endl ;

if (FAILED(hr))
{
ErrorMessage(hr) ;
}

}

//
// Print out the COM/OLE error string for an HRESULT.
//
void ErrorMessage(HRESULT hr)
{
void* pMsgBuf ;

::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &pMsgBuf,
0,
NULL) ;

cout << "Error (" << hex << hr << "): "
<< (LPTSTR)pMsgBuf << endl ;

// Free the buffer.
LocalFree(pMsgBuf) ;

}

} ; // End Namespace Util

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics