From e900128ead7df961aff141ccaf6ec801a70b934c Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sun, 23 Nov 2003 12:13:39 +0000 Subject: [PATCH] logging using OutputDebugString() svn path=/trunk/; revision=6760 --- reactos/subsys/system/explorer/globals.h | 8 +++++- .../system/explorer/utility/shellclasses.cpp | 26 ++++++++++++------- .../system/explorer/utility/shellclasses.h | 6 +++++ .../system/explorer/utility/utility.cpp | 7 +++-- .../subsys/system/explorer/utility/utility.h | 7 +++-- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/reactos/subsys/system/explorer/globals.h b/reactos/subsys/system/explorer/globals.h index 8e2f0c9b18c..9ff4a36c2e3 100644 --- a/reactos/subsys/system/explorer/globals.h +++ b/reactos/subsys/system/explorer/globals.h @@ -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 diff --git a/reactos/subsys/system/explorer/utility/shellclasses.cpp b/reactos/subsys/system/explorer/utility/shellclasses.cpp index e09cd6850aa..dd3964ba96b 100644 --- a/reactos/subsys/system/explorer/utility/shellclasses.cpp +++ b/reactos/subsys/system/explorer/utility/shellclasses.cpp @@ -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); diff --git a/reactos/subsys/system/explorer/utility/shellclasses.h b/reactos/subsys/system/explorer/utility/shellclasses.h index 980492cb652..bab3e8b874c 100644 --- a/reactos/subsys/system/explorer/utility/shellclasses.h +++ b/reactos/subsys/system/explorer/utility/shellclasses.h @@ -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; diff --git a/reactos/subsys/system/explorer/utility/utility.cpp b/reactos/subsys/system/explorer/utility/utility.cpp index 235a0a4f729..7ac569d7c53 100644 --- a/reactos/subsys/system/explorer/utility/utility.cpp +++ b/reactos/subsys/system/explorer/utility/utility.cpp @@ -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); } diff --git a/reactos/subsys/system/explorer/utility/utility.h b/reactos/subsys/system/explorer/utility/utility.h index dcf02011ed6..a1d5d55a2f4 100644 --- a/reactos/subsys/system/explorer/utility/utility.h +++ b/reactos/subsys/system/explorer/utility/utility.h @@ -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;}