logging using OutputDebugString()

svn path=/trunk/; revision=6760
This commit is contained in:
Martin Fuchs 2003-11-23 12:13:39 +00:00
parent 2314762543
commit e900128ead
5 changed files with 40 additions and 14 deletions

View file

@ -45,7 +45,13 @@ extern struct ExplorerGlobals
#endif
} g_Globals;
#define LOG(x) if (g_Globals._log) _ftprintf(g_Globals._log, TEXT("%s\n"), (LPCTSTR)(x));
#undef LOG
#define LOG(x) \
{ \
if (g_Globals._log) _ftprintf(g_Globals._log, TEXT("%s\n"), (LPCTSTR)(x)); \
OutputDebugString(x); \
}
/// convenient loading of string resources

View file

@ -68,26 +68,34 @@ Context* Context::s_current = &Context::s_main;
// Exception Handler for COM exceptions
void HandleException(COMException& e, HWND hwnd)
String COMException::toString() const
{
TCHAR msg[4*BUFFER_LEN];
LPTSTR p = msg;
p += _stprintf(p, TEXT("%s"), e.ErrorMessage());
p += _stprintf(p, TEXT("%s"), super::ErrorMessage());
if (e._ctx)
p += _stprintf(p, TEXT("\nContext: %s"), e._ctx);
if (_ctx)
p += _stprintf(p, TEXT("\nContext: %s"), _ctx);
if (!e._obj.empty())
p += _stprintf(p, TEXT("\nObject: %s"), (LPCTSTR)e._obj);
if (!_obj.empty())
p += _stprintf(p, TEXT("\nObject: %s"), (LPCTSTR)_obj);
if (e._file)
if (_file)
#ifdef UNICODE
p += _stprintf(p, TEXT("\nLocation: %hs(%d)"), e._file, e._line);
p += _stprintf(p, TEXT("\nLocation: %hs(%d)"), _file, _line);
#else
p += _stprintf(p, TEXT("\nLocation: %s, line %d"), e._file, e._line);
p += _stprintf(p, TEXT("\nLocation: %s, line %d"), _file, _line);
#endif
return msg;
}
void HandleException(COMException& e, HWND hwnd)
{
String msg = e.toString();
SetLastError(0);
MessageBox(hwnd, msg, TEXT("ShellClasses COM Exception"), MB_ICONHAND|MB_OK);

View file

@ -106,6 +106,7 @@ struct COMException : public COMExceptionBase
_obj(Context::current()._obj),
_file(NULL), _line(0)
{
LOG(toString());
}
COMException(HRESULT hr, const char* file, int line)
@ -114,6 +115,7 @@ struct COMException : public COMExceptionBase
_obj(Context::current()._obj),
_file(file), _line(line)
{
LOG(toString());
}
COMException(HRESULT hr, const String& obj)
@ -123,6 +125,7 @@ struct COMException : public COMExceptionBase
_file(NULL), _line(0)
{
_ctx = Context::current()._ctx;
LOG(toString());
}
COMException(HRESULT hr, const String& obj, const char* file, int line)
@ -131,8 +134,11 @@ struct COMException : public COMExceptionBase
_obj(obj),
_file(file), _line(line)
{
LOG(toString());
}
String toString() const;
LPCTSTR _ctx;
String _obj;

View file

@ -98,10 +98,13 @@ void display_error(HWND hwnd, DWORD error) //@@ CONTEXT mit ausgeben
PTSTR msg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) {
LOG(msg);
MessageBox(hwnd, msg, TEXT("ROS Explorer"), MB_OK);
else
} else {
LOG(TEXT("display_error: Unknown Error"));
MessageBox(hwnd, TEXT("Unknown Error"), TEXT("ROS Explorer"), MB_OK);
}
LocalFree(msg);
}

View file

@ -85,6 +85,9 @@ using namespace _com_util;
#define BUFFER_LEN 1024
#define LOG(x) OutputDebugString(x)
/// initialization of windows common controls
struct CommonControlInit
{
@ -496,11 +499,11 @@ struct String
#ifdef UNICODE
String(LPCSTR s) {assign(s);}
String& operator=(LPCSTR s) {assign(s); return *this;}
void assign(LPCSTR s) {TCHAR b[BUFFER_LEN]; MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN); super::assign(b);}
void assign(LPCSTR s) {TCHAR b[BUFFER_LEN]; super::assign(b, MultiByteToWideChar(CP_ACP, 0, s, -1, b, BUFFER_LEN));}
#else
String(LPCWSTR s) {assign(s);}
String& operator=(LPCWSTR s) {assign(s); return *this;}
void assign(LPCWSTR s) {char b[BUFFER_LEN]; WideCharToMultiByte(CP_ACP, 0, s, -1, b, BUFFER_LEN, 0, 0); super::assign(b);}
void assign(LPCWSTR s) {char b[BUFFER_LEN]; super::assign(b, WideCharToMultiByte(CP_ACP, 0, s, -1, b, BUFFER_LEN, 0, 0));}
#endif
String& operator=(LPCTSTR s) {super::assign(s); return *this;}