Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

372 lines
9.1 KiB

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