debug.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // debug.c
  4. //
  5. ////////////////////////////////////////////////////////////////////////////////
  6. #include "priv.h"
  7. #pragma hdrstop
  8. #ifdef DEBUG
  9. #ifndef WINNT
  10. #include <windows.h>
  11. //#include <stdlib.h>
  12. //#include <stdio.h>
  13. #include "debug.h"
  14. #endif
  15. void
  16. _Assert
  17.   (DWORD dw, LPSTR lpszExp, LPSTR lpszFile, DWORD dwLine)
  18. {
  19.   DWORD dwT;
  20.   TCHAR lpszT[256];
  21.   wsprintf (lpszT, TEXT("Assertion %hs Failed.nn%hs, line# %ldnnYes to continue, No to debug, Cancel to exit"), lpszExp, lpszFile, dwLine);
  22.   dwT = MessageBox (GetFocus(), lpszT, TEXT("Assertion Failed!"), MB_YESNOCANCEL);
  23.   switch (dwT)
  24.   {
  25.     case IDCANCEL :
  26.       //exit (1);
  27.         FatalExit(1);
  28.     case IDNO :
  29.       DebugTrap;
  30.   }
  31. }
  32. void
  33. _AssertSz
  34.   (DWORD dw, LPSTR lpszExp, LPTSTR lpsz, LPSTR lpszFile, DWORD dwLine)
  35. {
  36.   DWORD dwT;
  37.   TCHAR lpszT[512];
  38.   wsprintf (lpszT, TEXT("Assertion %hs Failed.nn%sn%hs, line# %ldnnYes to continue, No to debug, Cancel to exit"), lpszExp, lpsz, lpszFile, dwLine);
  39.   dwT = MessageBox (GetFocus(), lpszT, TEXT("Assertion Failed!"), MB_YESNOCANCEL);
  40.   switch (dwT)
  41.   {
  42.     case IDCANCEL:
  43.       //exit (1);
  44.                 FatalExit(1);
  45.     case IDNO :
  46.       DebugTrap;
  47.   }
  48. }
  49. #ifdef LOTS_O_DEBUG
  50. #include <windows.h>
  51. #include <winerror.h>
  52. #include <oleauto.h>
  53. #include "debug.h"
  54. void
  55. _DebugHr
  56.   (HRESULT hr, LPTSTR lpszFile, DWORD dwLine)
  57. {
  58.   TCHAR lpstzT[512];
  59.   switch (hr) {
  60.     case S_OK :
  61.       return;
  62.     case STG_E_INVALIDNAME:
  63.       wsprintf (lpstzT, TEXT("tBogus filenamenn%s, line# %ldn"),lpszFile, dwLine);
  64.       break;
  65.     case STG_E_INVALIDFUNCTION :
  66.       wsprintf (lpstzT, TEXT("tInvalid Functionnn%s, line# %ldn"),lpszFile, dwLine);
  67.       break;
  68.     case STG_E_FILENOTFOUND:
  69.       wsprintf (lpstzT, TEXT("tFile not foundnn%s, line# %ldn"),lpszFile, dwLine);
  70.       break;
  71.     case STG_E_INVALIDFLAG:
  72.       wsprintf (lpstzT, TEXT("tBogus flagnn%s, line# %ldn"),lpszFile, dwLine);
  73.       break;
  74.     case STG_E_INVALIDPOINTER:
  75.       wsprintf (lpstzT, TEXT("tBogus pointernn%s, line# %ldn"),lpszFile, dwLine);
  76.       break;
  77.     case STG_E_ACCESSDENIED:
  78.       wsprintf (lpstzT, TEXT("tAccess Deniednn%s, line# %ldn"),lpszFile, dwLine);
  79.       break;
  80.     case STG_E_INSUFFICIENTMEMORY :
  81.     case E_OUTOFMEMORY            :
  82.       wsprintf (lpstzT, TEXT("tInsufficient Memorynn%s, line# %ldn"),lpszFile, dwLine);
  83.       break;
  84.     case E_INVALIDARG :
  85.       wsprintf (lpstzT, TEXT("tInvalid argumentnn%s, line# %ldn"),lpszFile, dwLine);
  86.       break;
  87.     case TYPE_E_UNKNOWNLCID:
  88.       wsprintf (lpstzT, TEXT("tUnknown LCIDnn%s, line# %ldn"),lpszFile, dwLine);
  89.       break;
  90.     case TYPE_E_CANTLOADLIBRARY:
  91.       wsprintf (lpstzT, TEXT("tCan't load typelib or dllnn%s, line# %ldn"),lpszFile, dwLine);
  92.       break;
  93.     case TYPE_E_INVDATAREAD:
  94.       wsprintf (lpstzT, TEXT("tCan't read filenn%s, line# %ldn"),lpszFile, dwLine);
  95.       break;
  96.     case TYPE_E_INVALIDSTATE:
  97.       wsprintf (lpstzT, TEXT("tTypelib couldn't be openednn%s, line# %ldn"),lpszFile, dwLine);
  98.       break;
  99.     case TYPE_E_IOERROR:
  100.       wsprintf (lpstzT, TEXT("tI/O errornn%s, line# %ldn"),lpszFile, dwLine);
  101.       break;
  102.     default:
  103.       wsprintf (lpstzT, TEXT("tUnknown HRESULT %lx (%ld) nn%s, line# %ldn"),hr, hr, lpszFile, dwLine);
  104.   }
  105.   MessageBox (GetFocus(), lpstzT, NULL, MB_OK);
  106.   return;
  107. }
  108. void
  109. _DebugGUID (GUID g)
  110. {
  111.   TCHAR lpsz[200];
  112.   wsprintf (lpsz, TEXT("GUID is: %lx-%hx-%hx-%hx%hx-%hx%hx%hx%hx%hx%hx"),
  113.            g.Data1, g.Data2, g.Data3, g.Data4[0], g.Data4[1], g.Data4[2], g.Data4[3],
  114.            g.Data4[4], g.Data4[5], g.Data4[6], g.Data4[7]);
  115.   DebugSz (lpsz);
  116. }
  117. #endif // LOTS_O_DEBUG
  118. #endif // DEBUG