D:/Zythum/DinoKod/Common/Error.cpp

00001 //---------------------------------------------------------------------------------------------
00002 //      This file is a part of "DinoKod".
00003 //      Copyright © 2003 Dino Productions. All Rights Reserved.
00004 //      
00005 //      File                    : Error.cpp
00006 //      Author                  : Sebastien LEIX        sebastien.leix@wanadoo.fr
00007 //      Date                    : 
00008 //      Modification    :
00009 //
00010 //---------------------------------------------------------------------------------------------
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 
00014 #include "Common/Console.h"
00015 #include "Common/Error.h"
00016 
00017 //---------------------------------------------------------------------------------------------------------------------
00018 KError::KError()
00019 {
00020 }
00021 
00022 //---------------------------------------------------------------------------------------------------------------------
00023 KError::~KError()
00024 {
00025 }
00026 
00027 //---------------------------------------------------------------------------------------------------------------------
00028 void KError::FatalError( HWND hWnd, const char *format, ... )
00029 {
00030         char    buf[1024];
00031         va_list arg_ptr;
00032 
00033         if( !hWnd )
00034                 hWnd = GetActiveWindow();
00035 
00036         va_start(arg_ptr, format);
00037         _vsnprintf(buf, sizeof(buf), format, arg_ptr);
00038 
00039         g_Console << KCMT_ERROR << buf << KENDL;
00040 
00041 #ifdef _DEBUG
00042         strcat( buf,"\nDebug ?" );
00043         int     Button = MessageBox(    hWnd,
00044                                                                 buf,
00045                                                                 " Fatal Error",
00046                                                                 MB_SETFOREGROUND | MB_YESNO | MB_ICONSTOP );
00047         
00048         if( Button == IDYES )
00049                 DebugBreak();
00050 
00051         ExitProcess( -1 );
00052         return;
00053 #else
00054         MessageBox( hWnd,
00055                                 buf,
00056                                 "Fatal Error",
00057                                 MB_SETFOREGROUND | MB_OK | MB_ICONSTOP );
00058         
00059         ExitProcess( -1 );
00060 //      PostQuitMessage( -1 );
00061 #endif _DEBUG
00062 }
00063 
00064 //---------------------------------------------------------------------------------------------------------------------
00065 void KError::FatalError( HWND hWnd, u32 ErrorCode, const char *format, ... )
00066 {
00067         char    buf[1024];
00068         va_list arg_ptr;
00069 
00070         if( !hWnd )
00071                 hWnd = GetActiveWindow();
00072 
00073         va_start(arg_ptr, format);
00074         _vsnprintf(buf, sizeof(buf), format, arg_ptr);
00075 
00076         LPVOID lpMsgBuf = NULL;
00077         FormatMessage( 
00078                         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00079                         FORMAT_MESSAGE_FROM_SYSTEM | 
00080                         FORMAT_MESSAGE_IGNORE_INSERTS,
00081                         NULL,
00082                         GetLastError(),
00083                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00084                         (LPTSTR) &lpMsgBuf,
00085                         0,
00086                         NULL 
00087                 );
00088 
00089         FatalError( hWnd, "%s\nError : %s", buf, lpMsgBuf );
00090         
00091         LocalFree( lpMsgBuf );
00092 }  
00093 
00094 //---------------------------------------------------------------------------------------------------------------------
00095 void KError::Error( HWND hWnd, const char *format, ...)
00096 {
00097         char    buf[1024];
00098         va_list arg_ptr;
00099 
00100         if( !hWnd )
00101                 hWnd = GetActiveWindow();
00102 
00103         va_start(arg_ptr, format);
00104         _vsnprintf(buf, sizeof(buf), format, arg_ptr);
00105 
00106         g_Console << KCMT_ERROR << buf << KENDL;
00107 
00108 #ifdef _DEBUG
00109         strcat( buf,"\nDebug ?" );
00110         int     Button = MessageBox(    hWnd,
00111                                                                 buf,
00112                                                                 "Stupid Error",
00113                                                                 MB_SETFOREGROUND | MB_YESNO | MB_ICONSTOP );
00114         
00115         if( Button == IDYES )
00116                 DebugBreak();
00117         return;
00118 #else
00119         MessageBox( hWnd,
00120                                 buf,
00121                                 "Error",
00122                                 MB_SETFOREGROUND | MB_OK | MB_ICONSTOP );
00123 #endif
00124 }  
00125 
00126 //---------------------------------------------------------------------------------------------------------------------
00127 void KError::Error( HWND hWnd, u32 ErrorCode, const char *format, ...)
00128 {
00129         char    buf[1024];
00130         va_list arg_ptr;
00131 
00132         if( !hWnd )
00133                 hWnd = GetActiveWindow();
00134 
00135         va_start(arg_ptr, format);
00136         _vsnprintf(buf, sizeof(buf), format, arg_ptr);
00137 
00138         LPVOID lpMsgBuf = NULL;
00139         FormatMessage( 
00140                         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00141                         FORMAT_MESSAGE_FROM_SYSTEM | 
00142                         FORMAT_MESSAGE_IGNORE_INSERTS,
00143                         NULL,
00144                         GetLastError(),
00145                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00146                         (LPTSTR) &lpMsgBuf,
00147                         0,
00148                         NULL 
00149                 );
00150 
00151         Error( hWnd, "%s\nError : %s", buf, lpMsgBuf );
00152         
00153         LocalFree( lpMsgBuf );
00154 }  
00155 
00156 //---------------------------------------------------------------------------------------------------------------------
00157 void KError::Warning( HWND hWnd, const char *format, ...)
00158 {
00159         char    buf[1024];
00160         va_list arg_ptr;
00161 
00162         if( !hWnd )
00163                 hWnd = GetActiveWindow();
00164 
00165         va_start(arg_ptr, format);
00166         _vsnprintf(buf, sizeof(buf), format, arg_ptr);
00167 
00168         g_Console << KCMT_WARNING << buf << KENDL;
00169 }  
00170 
00171 //---------------------------------------------------------------------------------------------------------------------
00172 void KError::Debug( HWND hWnd, const char *format, ... )
00173 {
00174 #ifdef _DEBUG
00175         char    buf[1024];
00176         va_list arg_ptr;
00177 
00178         if( !hWnd )
00179                 hWnd = GetActiveWindow();
00180 
00181         va_start(arg_ptr, format);
00182         _vsnprintf(buf, sizeof(buf), format, arg_ptr);
00183 
00184         g_Console << KCMT_WARNING << buf << KENDL;
00185 #endif
00186 }

Generated on Sun Mar 25 20:02:10 2007 for Zythum Project by  doxygen 1.5.1-p1