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

Windows编程

开发平台:

Visual C++

  1. /*************************************************************************
  2. **
  3. **    OLE 2.0 Common Utilities
  4. **
  5. **    dbgutil.h
  6. **
  7. **    This file contains file contains functions to support debug output.
  8. **
  9. **    (c) Copyright Microsoft Corp. 1990 - 1996 All Rights Reserved
  10. **
  11. *************************************************************************/
  12. #define STRICT  1
  13. #include "olestd.h"
  14. static int s_nDbgIndent = 0;        // indent level for debug message
  15. #if defined( _DEBUG )
  16. static int s_nDbgLevel = 0;   // default dbg level printed
  17. #else
  18. static int s_nDbgLevel = 0;   // default dbg level printed
  19. #endif
  20. STDAPI_(void) OleDbgPrint(
  21.                 int     nDbgLvl,
  22.                 LPSTR   lpszPrefix,
  23.                 LPSTR   lpszMsg,
  24.                 int     nIndent
  25. )
  26. {
  27.         if (nDbgLvl <= s_nDbgLevel)
  28.                 OleDbgPrintAlways(lpszPrefix, lpszMsg, nIndent);
  29. }
  30. STDAPI_(void) OleDbgPrintAlways(LPSTR lpszPrefix, LPSTR lpszMsg, int nIndent)
  31. {
  32.         int i;
  33.         if (nIndent < 0)
  34.                 OleDbgIndent(nIndent);
  35.         if (lpszPrefix && *lpszPrefix != '') {
  36.                 OutputDebugString("| ");
  37.                 for (i = 0; i < s_nDbgIndent; i++)
  38.                         OutputDebugString("----");
  39.                 OutputDebugString(lpszPrefix);
  40.                 OutputDebugString(": ");
  41.         }
  42.         OutputDebugString(lpszMsg);
  43.         if (nIndent > 0)
  44.                 OleDbgIndent(nIndent);
  45. }
  46. STDAPI_(void) OleDbgSetDbgLevel(int nDbgLvl)
  47. {
  48.         s_nDbgLevel = nDbgLvl;
  49. }
  50. STDAPI_(int) OleDbgGetDbgLevel( void )
  51. {
  52.         return s_nDbgLevel;
  53. }
  54. STDAPI_(void) OleDbgIndent(int n)
  55. {
  56.         switch (n) {
  57.                 case -1:
  58.                         s_nDbgIndent--;
  59.                         break;
  60.                 case 1:
  61.                         s_nDbgIndent++;
  62.                         break;
  63.                 case -2:
  64.                         s_nDbgIndent = 0;
  65.                         break;
  66.         }
  67. }
  68. STDAPI_(void) OleDbgPrintRefCnt(
  69.                 int         nDbgLvl,
  70.                 LPSTR       lpszPrefix,
  71.                 LPSTR       lpszMsg,
  72.                 LPVOID      lpObj,
  73.                 ULONG       refcnt
  74. )
  75. {
  76.         if (nDbgLvl <= s_nDbgLevel)
  77.                 OleDbgPrintRefCntAlways(lpszPrefix, lpszMsg, lpObj, refcnt);
  78. }
  79. STDAPI_(void) OleDbgPrintRefCntAlways(
  80.                 LPSTR       lpszPrefix,
  81.                 LPSTR       lpszMsg,
  82.                 LPVOID      lpObj,
  83.                 ULONG       refcnt
  84. )
  85. {
  86. #if defined( _DEBUG )
  87.         char szBuf[256];
  88.         wsprintf(szBuf, "[obj=(0x%lx) cnt=%ld] %s", lpObj, refcnt, lpszMsg);
  89.         OleDbgPrintAlways(lpszPrefix, szBuf, 0);
  90. #endif
  91. }
  92. STDAPI_(void) OleDbgPrintRect(
  93.                 int         nDbgLvl,
  94.                 LPSTR       lpszPrefix,
  95.                 LPSTR       lpszMsg,
  96.                 LPRECT      lpRect
  97. )
  98. {
  99.         if (nDbgLvl <= s_nDbgLevel)
  100.                 OleDbgPrintRectAlways(lpszPrefix, lpszMsg, lpRect);
  101. }
  102. STDAPI_(void) OleDbgPrintRectAlways(
  103.                 LPSTR       lpszPrefix,
  104.                 LPSTR       lpszMsg,
  105.                 LPRECT      lpRect
  106. )
  107. {
  108. #if defined( _DEBUG )
  109.         char szBuf[256];
  110.         wsprintf(
  111.                         szBuf,
  112.                         "%s: (%d,%d)-(%d,%d) %dx%drn",
  113.                         lpszMsg,
  114.                         lpRect->left,
  115.                         lpRect->top,
  116.                         lpRect->right,
  117.                         lpRect->bottom,
  118.                         (lpRect->right-lpRect->left),
  119.                         (lpRect->bottom-lpRect->top)
  120.         );
  121.         OleDbgPrintAlways(lpszPrefix, szBuf, 0);
  122. #endif
  123. }
  124. #define CASE_SCODE(sc)  
  125.                 case sc: 
  126.                         lstrcpy(/*(LPSTR)*/szErrName, /*(LPSTR)*/#sc); 
  127.                         break;
  128. STDAPI_(void) OleDbgPrintScodeAlways(LPSTR lpszPrefix, LPSTR lpszMsg, SCODE sc)
  129. {
  130. #if defined( _DEBUG )
  131.         char szBuf[256];
  132.         char szErrName[40];
  133.         switch (sc) {
  134.                 /* SCODE's defined in SCODE.H */
  135.                 CASE_SCODE(S_OK)
  136.                 CASE_SCODE(S_FALSE)
  137.                 CASE_SCODE(E_UNEXPECTED)
  138.                 CASE_SCODE(E_OUTOFMEMORY)
  139.                 CASE_SCODE(E_INVALIDARG)
  140.                 CASE_SCODE(E_NOINTERFACE)
  141.                 CASE_SCODE(E_POINTER)
  142.                 CASE_SCODE(E_HANDLE)
  143.                 CASE_SCODE(E_ABORT)
  144.                 CASE_SCODE(E_FAIL)
  145.                 CASE_SCODE(E_ACCESSDENIED)
  146.                 /* SCODE's defined in OLE2.H */
  147.                 CASE_SCODE(OLE_E_OLEVERB)
  148.                 CASE_SCODE(OLE_E_ADVF)
  149.                 CASE_SCODE(OLE_E_ENUM_NOMORE)
  150.                 CASE_SCODE(OLE_E_ADVISENOTSUPPORTED)
  151.                 CASE_SCODE(OLE_E_NOCONNECTION)
  152.                 CASE_SCODE(OLE_E_NOTRUNNING)
  153.                 CASE_SCODE(OLE_E_NOCACHE)
  154.                 CASE_SCODE(OLE_E_BLANK)
  155.                 CASE_SCODE(OLE_E_CLASSDIFF)
  156.                 CASE_SCODE(OLE_E_CANT_GETMONIKER)
  157.                 CASE_SCODE(OLE_E_CANT_BINDTOSOURCE)
  158.                 CASE_SCODE(OLE_E_STATIC)
  159.                 CASE_SCODE(OLE_E_PROMPTSAVECANCELLED)
  160.                 CASE_SCODE(OLE_E_INVALIDRECT)
  161.                 CASE_SCODE(OLE_E_WRONGCOMPOBJ)
  162.                 CASE_SCODE(OLE_E_INVALIDHWND)
  163.                 CASE_SCODE(OLE_E_NOT_INPLACEACTIVE)
  164.                 CASE_SCODE(OLE_E_CANTCONVERT)
  165.                 CASE_SCODE(OLE_E_NOSTORAGE)
  166.                 CASE_SCODE(DV_E_FORMATETC)
  167.                 CASE_SCODE(DV_E_DVTARGETDEVICE)
  168.                 CASE_SCODE(DV_E_STGMEDIUM)
  169.                 CASE_SCODE(DV_E_STATDATA)
  170.                 CASE_SCODE(DV_E_LINDEX)
  171.                 CASE_SCODE(DV_E_TYMED)
  172.                 CASE_SCODE(DV_E_CLIPFORMAT)
  173.                 CASE_SCODE(DV_E_DVASPECT)
  174.                 CASE_SCODE(DV_E_DVTARGETDEVICE_SIZE)
  175.                 CASE_SCODE(DV_E_NOIVIEWOBJECT)
  176.                 CASE_SCODE(OLE_S_USEREG)
  177.                 CASE_SCODE(OLE_S_STATIC)
  178.                 CASE_SCODE(OLE_S_MAC_CLIPFORMAT)
  179.                 CASE_SCODE(CONVERT10_E_OLESTREAM_GET)
  180.                 CASE_SCODE(CONVERT10_E_OLESTREAM_PUT)
  181.                 CASE_SCODE(CONVERT10_E_OLESTREAM_FMT)
  182.                 CASE_SCODE(CONVERT10_E_OLESTREAM_BITMAP_TO_DIB)
  183.                 CASE_SCODE(CONVERT10_E_STG_FMT)
  184.                 CASE_SCODE(CONVERT10_E_STG_NO_STD_STREAM)
  185.                 CASE_SCODE(CONVERT10_E_STG_DIB_TO_BITMAP)
  186.                 CASE_SCODE(CONVERT10_S_NO_PRESENTATION)
  187.                 CASE_SCODE(CLIPBRD_E_CANT_OPEN)
  188.                 CASE_SCODE(CLIPBRD_E_CANT_EMPTY)
  189.                 CASE_SCODE(CLIPBRD_E_CANT_SET)
  190.                 CASE_SCODE(CLIPBRD_E_BAD_DATA)
  191.                 CASE_SCODE(CLIPBRD_E_CANT_CLOSE)
  192.                 CASE_SCODE(DRAGDROP_E_NOTREGISTERED)
  193.                 CASE_SCODE(DRAGDROP_E_ALREADYREGISTERED)
  194.                 CASE_SCODE(DRAGDROP_E_INVALIDHWND)
  195.                 CASE_SCODE(DRAGDROP_S_DROP)
  196.                 CASE_SCODE(DRAGDROP_S_CANCEL)
  197.                 CASE_SCODE(DRAGDROP_S_USEDEFAULTCURSORS)
  198.                 CASE_SCODE(OLEOBJ_E_NOVERBS)
  199.                 CASE_SCODE(OLEOBJ_E_INVALIDVERB)
  200.                 CASE_SCODE(OLEOBJ_S_INVALIDVERB)
  201.                 CASE_SCODE(OLEOBJ_S_CANNOT_DOVERB_NOW)
  202.                 CASE_SCODE(OLEOBJ_S_INVALIDHWND)
  203.                 CASE_SCODE(INPLACE_E_NOTUNDOABLE)
  204.                 CASE_SCODE(INPLACE_E_NOTOOLSPACE)
  205.                 CASE_SCODE(INPLACE_S_TRUNCATED)
  206.                 /* SCODE's defined in COMPOBJ.H */
  207.                 CASE_SCODE(CO_E_NOTINITIALIZED)
  208.                 CASE_SCODE(CO_E_ALREADYINITIALIZED)
  209.                 CASE_SCODE(CO_E_CANTDETERMINECLASS)
  210.                 CASE_SCODE(CO_E_CLASSSTRING)
  211.                 CASE_SCODE(CO_E_IIDSTRING)
  212.                 CASE_SCODE(CO_E_APPNOTFOUND)
  213.                 CASE_SCODE(CO_E_APPSINGLEUSE)
  214.                 CASE_SCODE(CO_E_ERRORINAPP)
  215.                 CASE_SCODE(CO_E_DLLNOTFOUND)
  216.                 CASE_SCODE(CO_E_ERRORINDLL)
  217.                 CASE_SCODE(CO_E_WRONGOSFORAPP)
  218.                 CASE_SCODE(CO_E_OBJNOTREG)
  219.                 CASE_SCODE(CO_E_OBJISREG)
  220.                 CASE_SCODE(CO_E_OBJNOTCONNECTED)
  221.                 CASE_SCODE(CO_E_APPDIDNTREG)
  222.                 CASE_SCODE(CLASS_E_NOAGGREGATION)
  223.                 CASE_SCODE(CLASS_E_CLASSNOTAVAILABLE)
  224.                 CASE_SCODE(REGDB_E_READREGDB)
  225.                 CASE_SCODE(REGDB_E_WRITEREGDB)
  226.                 CASE_SCODE(REGDB_E_KEYMISSING)
  227.                 CASE_SCODE(REGDB_E_INVALIDVALUE)
  228.                 CASE_SCODE(REGDB_E_CLASSNOTREG)
  229.                 CASE_SCODE(REGDB_E_IIDNOTREG)
  230.                 CASE_SCODE(RPC_E_CALL_REJECTED)
  231.                 CASE_SCODE(RPC_E_CALL_CANCELED)
  232.                 CASE_SCODE(RPC_E_CANTPOST_INSENDCALL)
  233.                 CASE_SCODE(RPC_E_CANTCALLOUT_INASYNCCALL)
  234.                 CASE_SCODE(RPC_E_CANTCALLOUT_INEXTERNALCALL)
  235.                 CASE_SCODE(RPC_E_CONNECTION_TERMINATED)
  236.                 CASE_SCODE(RPC_E_SERVER_DIED)
  237.                 CASE_SCODE(RPC_E_CLIENT_DIED)
  238.                 CASE_SCODE(RPC_E_INVALID_DATAPACKET)
  239.                 CASE_SCODE(RPC_E_CANTTRANSMIT_CALL)
  240.                 CASE_SCODE(RPC_E_CLIENT_CANTMARSHAL_DATA)
  241.                 CASE_SCODE(RPC_E_CLIENT_CANTUNMARSHAL_DATA)
  242.                 CASE_SCODE(RPC_E_SERVER_CANTMARSHAL_DATA)
  243.                 CASE_SCODE(RPC_E_SERVER_CANTUNMARSHAL_DATA)
  244.                 CASE_SCODE(RPC_E_INVALID_DATA)
  245.                 CASE_SCODE(RPC_E_INVALID_PARAMETER)
  246.                 CASE_SCODE(RPC_E_UNEXPECTED)
  247.                 /* SCODE's defined in DVOBJ.H */
  248.                 CASE_SCODE(DATA_S_SAMEFORMATETC)
  249.                 CASE_SCODE(VIEW_E_DRAW)
  250.                 CASE_SCODE(VIEW_S_ALREADY_FROZEN)
  251.                 CASE_SCODE(CACHE_E_NOCACHE_UPDATED)
  252.                 CASE_SCODE(CACHE_S_FORMATETC_NOTSUPPORTED)
  253.                 CASE_SCODE(CACHE_S_SAMECACHE)
  254.                 CASE_SCODE(CACHE_S_SOMECACHES_NOTUPDATED)
  255.                 /* SCODE's defined in STORAGE.H */
  256.                 CASE_SCODE(STG_E_INVALIDFUNCTION)
  257.                 CASE_SCODE(STG_E_FILENOTFOUND)
  258.                 CASE_SCODE(STG_E_PATHNOTFOUND)
  259.                 CASE_SCODE(STG_E_TOOMANYOPENFILES)
  260.                 CASE_SCODE(STG_E_ACCESSDENIED)
  261.                 CASE_SCODE(STG_E_INVALIDHANDLE)
  262.                 CASE_SCODE(STG_E_INSUFFICIENTMEMORY)
  263.                 CASE_SCODE(STG_E_INVALIDPOINTER)
  264.                 CASE_SCODE(STG_E_NOMOREFILES)
  265.                 CASE_SCODE(STG_E_DISKISWRITEPROTECTED)
  266.                 CASE_SCODE(STG_E_SEEKERROR)
  267.                 CASE_SCODE(STG_E_WRITEFAULT)
  268.                 CASE_SCODE(STG_E_READFAULT)
  269.                 CASE_SCODE(STG_E_SHAREVIOLATION)
  270.                 CASE_SCODE(STG_E_LOCKVIOLATION)
  271.                 CASE_SCODE(STG_E_FILEALREADYEXISTS)
  272.                 CASE_SCODE(STG_E_INVALIDPARAMETER)
  273.                 CASE_SCODE(STG_E_MEDIUMFULL)
  274.                 CASE_SCODE(STG_E_ABNORMALAPIEXIT)
  275.                 CASE_SCODE(STG_E_INVALIDHEADER)
  276.                 CASE_SCODE(STG_E_INVALIDNAME)
  277.                 CASE_SCODE(STG_E_UNKNOWN)
  278.                 CASE_SCODE(STG_E_UNIMPLEMENTEDFUNCTION)
  279.                 CASE_SCODE(STG_E_INVALIDFLAG)
  280.                 CASE_SCODE(STG_E_INUSE)
  281.                 CASE_SCODE(STG_E_NOTCURRENT)
  282.                 CASE_SCODE(STG_E_REVERTED)
  283.                 CASE_SCODE(STG_E_CANTSAVE)
  284.                 CASE_SCODE(STG_E_OLDFORMAT)
  285.                 CASE_SCODE(STG_E_OLDDLL)
  286.                 CASE_SCODE(STG_E_SHAREREQUIRED)
  287.                 CASE_SCODE(STG_E_NOTFILEBASEDSTORAGE)
  288.                 CASE_SCODE(STG_E_EXTANTMARSHALLINGS)
  289.                 CASE_SCODE(STG_S_CONVERTED)
  290.                 /* SCODE's defined in MONIKER.H */
  291.                 CASE_SCODE(MK_E_CONNECTMANUALLY)
  292.                 CASE_SCODE(MK_E_EXCEEDEDDEADLINE)
  293.                 CASE_SCODE(MK_E_NEEDGENERIC)
  294.                 CASE_SCODE(MK_E_UNAVAILABLE)
  295.                 CASE_SCODE(MK_E_SYNTAX)
  296.                 CASE_SCODE(MK_E_NOOBJECT)
  297.                 CASE_SCODE(MK_E_INVALIDEXTENSION)
  298.                 CASE_SCODE(MK_E_INTERMEDIATEINTERFACENOTSUPPORTED)
  299.                 CASE_SCODE(MK_E_NOTBINDABLE)
  300.                 CASE_SCODE(MK_E_NOTBOUND)
  301.                 CASE_SCODE(MK_E_CANTOPENFILE)
  302.                 CASE_SCODE(MK_E_MUSTBOTHERUSER)
  303.                 CASE_SCODE(MK_E_NOINVERSE)
  304.                 CASE_SCODE(MK_E_NOSTORAGE)
  305.                 CASE_SCODE(MK_E_NOPREFIX)
  306.                 CASE_SCODE(MK_S_REDUCED_TO_SELF)
  307.                 CASE_SCODE(MK_S_ME)
  308.                 CASE_SCODE(MK_S_HIM)
  309.                 CASE_SCODE(MK_S_US)
  310.                 CASE_SCODE(MK_S_MONIKERALREADYREGISTERED)
  311.                 default:
  312.                         lstrcpy(szErrName, "UNKNOWN SCODE");
  313.         }
  314.         wsprintf(szBuf, "%s %s (0x%lx)n", lpszMsg, /*(LPSTR)*/szErrName, sc);
  315.         OleDbgPrintAlways(lpszPrefix, szBuf, 0);
  316. #endif  // _DEBUG
  317. }