DBUGIT.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:7k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // --------------------------------------------------------------------------
  2. #define TraceTag     TRACEFUNC
  3. #define TraceError(_sz,_x)   TRACEFUNC(NULL,"ERROR: %s %08x",_sz,_x)
  4. #define DoTagsDialog()
  5. #define TagRegister 0;
  6. #define RestoreDefaultDebugState()
  7. #define tagNull      __LINE__,NULL
  8. #define tagUI        __LINE__,"ui"        
  9. #define tagUIOther   __LINE__,"uiother"
  10. #define tagMouse     __LINE__,"mouse"
  11. #define tagEngine    __LINE__,"engine"
  12. #define tagEngineMin __LINE__,"enginemin"
  13. #define tagForm      __LINE__,"form"
  14. #define tagFormFunc  __LINE__,"formfunc"
  15. #define tagFuncTriv  __LINE__,"functriv"
  16. #define AssertSz(_x,_sz) if (!(_x)) ASSERTFUNC(_sz,__LINE__,__FILE__,#_x);
  17. #define Assert(_x) AssertSz(_x,"assertion")
  18. #define ASSERTDATA
  19. #define pdebug
  20. #define stddbgmin NULL
  21. #define stddbg    NULL
  22. #define NYI(_x) AssertSz(0,_x)
  23. // --------------------------------------------------------------------------
  24. #ifdef DEBUG
  25. void _cdecl TRACEFUNC(int line, char * tag, char * szFmt, ...)
  26. #ifdef DEBUG_CODE
  27. {
  28.     va_list valMarker;
  29.     static char rgch[1024];
  30.     static char szTraceNumber[32];
  31.     static char szLineNumber[32];
  32.     int  x,q;
  33.     if (tag && 1 != GetPrivateProfileInt("tag",tag, 1, "c:\trace.out")) return;
  34.     va_start(valMarker, szFmt);
  35.     wvsprintf(rgch, szFmt, valMarker);
  36.     lstrcat(rgch,"                                                                                                                                                      ");
  37.     rgch[125] = '';
  38.     wsprintf(rgch + 125,"<<< (%5d) ",line);
  39.     if (tag) lstrcat(rgch,tag);
  40.     else lstrcat(rgch,"NULL");
  41.     va_end(valMarker);
  42.     if (GetPrivateProfileInt ("trace", "trace", 0, "c:\trace.out"))
  43.     {
  44.         // ----- how many traces have we output
  45.         x = GetPrivateProfileInt ("trace", "last", 0, "c:\trace.out");
  46.         ++x;
  47.         wsprintf(szTraceNumber,"%d",x);
  48.         WritePrivateProfileString ("trace", "last", szTraceNumber, "c:\trace.out");
  49.         // ----- cat the file
  50.         FILE *fp;
  51.         fp = fopen("c:\trace.out", "a");
  52.         if (fp)
  53.         {
  54.             fprintf(fp,"%s",rgch);
  55.             fclose(fp);
  56.         }
  57.         else MessageBeep(0);
  58.         // ----- debug break
  59.         if (q=GetPrivateProfileInt ("trace", "break", 0, "c:\trace.out"))
  60.         {
  61.             if (q == x || -1 == q)
  62.                 MessageBox(NULL,rgch,"TRACE TAG",MB_OK);
  63.         }
  64.     }
  65. }
  66. #else
  67. ;
  68. #endif
  69. void ASSERTFUNC(char *sz,int line,char *file,char* string)
  70. #ifdef DEBUG_CODE
  71. {
  72.     static char rgch[1024];
  73.     TraceTag(tagNull,"nnASSERTION FAILURE !!!");
  74.     MessageBeep(0);
  75.     wsprintf(rgch,"%s(%d) (%s)n%s",file,line,string,sz);
  76.     TraceTag(tagNull,rgch);
  77.     MessageBox(NULL,rgch,"assertion failure",MB_TASKMODAL|MB_ABORTRETRYIGNORE);
  78. }
  79. #else
  80. ;
  81. #endif
  82. #ifndef IID_IPersistMessage
  83. #ifdef _WIN32
  84. #include <objbase.h>
  85. #else
  86. #include <compobj.h>
  87. #endif
  88. #include <mapiform.h>
  89. #else
  90. #pragma message("here we are now .. REFCLSID")
  91. #endif
  92. char *DumpCLSID(REFCLSID riid)
  93. #ifdef DEBUG_CODE
  94.     {
  95.     static char ach[44];
  96.     static char szName[256];
  97.     szName[0] = '';
  98. #ifdef _WIN32
  99.     if      (IsEqualIID(riid, IID_IUnknown            )) lstrcpy(szName,"IID_IUnknown           ");
  100.     else if (IsEqualIID(riid, IID_IClassFactory       )) lstrcpy(szName,"IID_IClassFactory      ");
  101.     else if (IsEqualIID(riid, IID_IMalloc             )) lstrcpy(szName,"IID_IMalloc            ");
  102.     else if (IsEqualIID(riid, IID_IMarshal            )) lstrcpy(szName,"IID_IMarshal           ");
  103.     else if (IsEqualIID(riid, IID_IRpcChannel         )) lstrcpy(szName,"IID_IRpcChannel        ");
  104.     else if (IsEqualIID(riid, IID_IRpcStub            )) lstrcpy(szName,"IID_IRpcStub           ");
  105.     else if (IsEqualIID(riid, IID_IStubManager        )) lstrcpy(szName,"IID_IStubManager       ");
  106.     else if (IsEqualIID(riid, IID_IRpcProxy           )) lstrcpy(szName,"IID_IRpcProxy          ");
  107.     else if (IsEqualIID(riid, IID_IProxyManager       )) lstrcpy(szName,"IID_IProxyManager      ");
  108.     else if (IsEqualIID(riid, IID_IPSFactory          )) lstrcpy(szName,"IID_IPSFactory         ");
  109.     else if (IsEqualIID(riid, IID_ILockBytes          )) lstrcpy(szName,"IID_ILockBytes         ");
  110.     else if (IsEqualIID(riid, IID_IStorage            )) lstrcpy(szName,"IID_IStorage           ");
  111.     else if (IsEqualIID(riid, IID_IStream             )) lstrcpy(szName,"IID_IStream            ");
  112.     else if (IsEqualIID(riid, IID_IEnumSTATSTG        )) lstrcpy(szName,"IID_IEnumSTATSTG       ");
  113.     else if (IsEqualIID(riid, IID_IBindCtx            )) lstrcpy(szName,"IID_IBindCtx           ");
  114.     else if (IsEqualIID(riid, IID_IMoniker            )) lstrcpy(szName,"IID_IMoniker           ");
  115.     else if (IsEqualIID(riid, IID_IRunningObjectTable )) lstrcpy(szName,"IID_IRunningObjectTable");
  116.     else if (IsEqualIID(riid, IID_IInternalMoniker    )) lstrcpy(szName,"IID_IInternalMoniker   ");
  117.     else if (IsEqualIID(riid, IID_IRootStorage        )) lstrcpy(szName,"IID_IRootStorage       ");
  118.     else if (IsEqualIID(riid, IID_IMessageFilter      )) lstrcpy(szName,"IID_IMessageFilter     ");
  119.     else if (IsEqualIID(riid, CLSID_StdMarshal        )) lstrcpy(szName,"CLSID_StdMarshal       ");
  120.     else if (IsEqualIID(riid, IID_IStdMarshalInfo     )) lstrcpy(szName,"IID_IStdMarshalInfo    ");
  121.     else if (IsEqualIID(riid, IID_IExternalConnection )) lstrcpy(szName,"IID_IExternalConnection");
  122.     else if (IsEqualIID(riid, IID_IPersistMessage     )) lstrcpy(szName,"IID_IPersistMessage    ");
  123.     else if (IsEqualIID(riid, IID_IMAPIMessageSite    )) lstrcpy(szName,"IID_IMAPIMessageSite   ");
  124.     else if (IsEqualIID(riid, IID_IMAPISession        )) lstrcpy(szName,"IID_IMAPISession       ");
  125.     else if (IsEqualIID(riid, IID_IMAPIViewContext    )) lstrcpy(szName,"IID_IMAPIViewContext   ");
  126.     else if (IsEqualIID(riid, IID_IMAPIViewAdviseSink )) lstrcpy(szName,"IID_IMAPIViewAdviseSink");
  127.     else if (IsEqualIID(riid, IID_IMAPIFormAdviseSink )) lstrcpy(szName,"IID_IMAPIFormAdviseSink");
  128.     else if (IsEqualIID(riid, IID_IMAPIFormInfo       )) lstrcpy(szName,"IID_IMAPIFormInfo      ");
  129.     else if (IsEqualIID(riid, IID_IMAPIFormMgr        )) lstrcpy(szName,"IID_IMAPIFormMgr       ");
  130.     else if (IsEqualIID(riid, IID_IMAPIFormContainer  )) lstrcpy(szName,"IID_IMAPIFormContainer ");
  131.     else if (IsEqualIID(riid, IID_IMAPIForm           )) lstrcpy(szName,"IID_IMAPIForm          ");
  132.     else                                                 lstrcpy(szName,"                       ");
  133. #endif
  134.     wsprintf(ach, "{%8.8lX-%4.4X-%4.4X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X} %s",
  135.         riid.Data1,
  136.         (int)riid.Data2,
  137.         (int)riid.Data3,
  138.         (int)riid.Data4[0],
  139.         (int)riid.Data4[1],
  140.         (int)riid.Data4[2],
  141.         (int)riid.Data4[3],
  142.         (int)riid.Data4[4],
  143.         (int)riid.Data4[5],
  144.         (int)riid.Data4[6],
  145.         (int)riid.Data4[7],
  146.         szName);
  147.     return ach;
  148.     }
  149. #else
  150. ;
  151. #endif
  152. #else
  153. #define TRACEFUNC   ;/##/
  154. //#define TRACEFUNC   
  155. #define ASSERTFUNC(_1,_2,_3,_4)
  156. #define DumpCLSID(_x) 0
  157. #endif