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.

419 lines
12 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. #define STRICT 1
  13. #include "ole2ui.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. LPTSTR lpszPrefix,
  23. LPTSTR lpszMsg,
  24. int nIndent
  25. )
  26. {
  27. if (nDbgLvl <= s_nDbgLevel)
  28. OleDbgPrintAlways(lpszPrefix, lpszMsg, nIndent);
  29. }
  30. STDAPI_(void) OleDbgPrintAlways(LPTSTR lpszPrefix, LPTSTR lpszMsg, int nIndent)
  31. {
  32. int i;
  33. if (nIndent < 0)
  34. OleDbgIndent(nIndent);
  35. if (lpszPrefix && *lpszPrefix != TEXT('\0')) {
  36. OutputDebugString(TEXT("| "));
  37. for (i = 0; i < s_nDbgIndent; i++)
  38. OutputDebugString(TEXT("----"));
  39. OutputDebugString(lpszPrefix);
  40. OutputDebugString(TEXT(": "));
  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. LPTSTR lpszPrefix,
  71. LPTSTR 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. LPTSTR lpszPrefix,
  81. LPTSTR lpszMsg,
  82. LPVOID lpObj,
  83. ULONG refcnt
  84. )
  85. {
  86. #if defined( _DEBUG )
  87. TCHAR szBuf[256];
  88. wsprintf(szBuf, TEXT("[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. LPTSTR lpszPrefix,
  95. LPTSTR lpszMsg,
  96. LPRECT lpRect
  97. )
  98. {
  99. if (nDbgLvl <= s_nDbgLevel)
  100. OleDbgPrintRectAlways(lpszPrefix, lpszMsg, lpRect);
  101. }
  102. STDAPI_(void) OleDbgPrintRectAlways(
  103. LPTSTR lpszPrefix,
  104. LPTSTR lpszMsg,
  105. LPRECT lpRect
  106. )
  107. {
  108. #if defined( _DEBUG )
  109. TCHAR szBuf[256];
  110. wsprintf(
  111. szBuf,
  112. TEXT("%s: (%d,%d)-(%d,%d) %dx%d\r\n"),
  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((LPTSTR)szErrName, (LPTSTR)#sc); \
  127. break;
  128. STDAPI_(void) OleDbgPrintScodeAlways(LPTSTR lpszPrefix, LPTSTR lpszMsg, SCODE sc)
  129. {
  130. #if defined( _DEBUG )
  131. TCHAR szBuf[256];
  132. TCHAR 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_CANTCALLOUT_AGAIN)
  247. CASE_SCODE(RPC_E_UNEXPECTED)
  248. /* SCODE's defined in DVOBJ.H */
  249. CASE_SCODE(DATA_S_SAMEFORMATETC)
  250. CASE_SCODE(VIEW_E_DRAW)
  251. CASE_SCODE(VIEW_S_ALREADY_FROZEN)
  252. CASE_SCODE(CACHE_E_NOCACHE_UPDATED)
  253. CASE_SCODE(CACHE_S_FORMATETC_NOTSUPPORTED)
  254. CASE_SCODE(CACHE_S_SAMECACHE)
  255. CASE_SCODE(CACHE_S_SOMECACHES_NOTUPDATED)
  256. /* SCODE's defined in STORAGE.H */
  257. CASE_SCODE(STG_E_INVALIDFUNCTION)
  258. CASE_SCODE(STG_E_FILENOTFOUND)
  259. CASE_SCODE(STG_E_PATHNOTFOUND)
  260. CASE_SCODE(STG_E_TOOMANYOPENFILES)
  261. CASE_SCODE(STG_E_ACCESSDENIED)
  262. CASE_SCODE(STG_E_INVALIDHANDLE)
  263. CASE_SCODE(STG_E_INSUFFICIENTMEMORY)
  264. CASE_SCODE(STG_E_INVALIDPOINTER)
  265. CASE_SCODE(STG_E_NOMOREFILES)
  266. CASE_SCODE(STG_E_DISKISWRITEPROTECTED)
  267. CASE_SCODE(STG_E_SEEKERROR)
  268. CASE_SCODE(STG_E_WRITEFAULT)
  269. CASE_SCODE(STG_E_READFAULT)
  270. CASE_SCODE(STG_E_SHAREVIOLATION)
  271. CASE_SCODE(STG_E_LOCKVIOLATION)
  272. CASE_SCODE(STG_E_FILEALREADYEXISTS)
  273. CASE_SCODE(STG_E_INVALIDPARAMETER)
  274. CASE_SCODE(STG_E_MEDIUMFULL)
  275. CASE_SCODE(STG_E_ABNORMALAPIEXIT)
  276. CASE_SCODE(STG_E_INVALIDHEADER)
  277. CASE_SCODE(STG_E_INVALIDNAME)
  278. CASE_SCODE(STG_E_UNKNOWN)
  279. CASE_SCODE(STG_E_UNIMPLEMENTEDFUNCTION)
  280. CASE_SCODE(STG_E_INVALIDFLAG)
  281. CASE_SCODE(STG_E_INUSE)
  282. CASE_SCODE(STG_E_NOTCURRENT)
  283. CASE_SCODE(STG_E_REVERTED)
  284. CASE_SCODE(STG_E_CANTSAVE)
  285. CASE_SCODE(STG_E_OLDFORMAT)
  286. CASE_SCODE(STG_E_OLDDLL)
  287. CASE_SCODE(STG_E_SHAREREQUIRED)
  288. CASE_SCODE(STG_E_NOTFILEBASEDSTORAGE)
  289. CASE_SCODE(STG_E_EXTANTMARSHALLINGS)
  290. CASE_SCODE(STG_S_CONVERTED)
  291. /* SCODE's defined in STORAGE.H */
  292. CASE_SCODE(MK_E_CONNECTMANUALLY)
  293. CASE_SCODE(MK_E_EXCEEDEDDEADLINE)
  294. CASE_SCODE(MK_E_NEEDGENERIC)
  295. CASE_SCODE(MK_E_UNAVAILABLE)
  296. CASE_SCODE(MK_E_SYNTAX)
  297. CASE_SCODE(MK_E_NOOBJECT)
  298. CASE_SCODE(MK_E_INVALIDEXTENSION)
  299. CASE_SCODE(MK_E_INTERMEDIATEINTERFACENOTSUPPORTED)
  300. CASE_SCODE(MK_E_NOTBINDABLE)
  301. CASE_SCODE(MK_E_NOTBOUND)
  302. CASE_SCODE(MK_E_CANTOPENFILE)
  303. CASE_SCODE(MK_E_MUSTBOTHERUSER)
  304. CASE_SCODE(MK_E_NOINVERSE)
  305. CASE_SCODE(MK_E_NOSTORAGE)
  306. CASE_SCODE(MK_E_NOPREFIX)
  307. CASE_SCODE(MK_S_REDUCED_TO_SELF)
  308. CASE_SCODE(MK_S_ME)
  309. CASE_SCODE(MK_S_HIM)
  310. CASE_SCODE(MK_S_US)
  311. CASE_SCODE(MK_S_MONIKERALREADYREGISTERED)
  312. default:
  313. lstrcpy(szErrName, TEXT("UNKNOWN SCODE"));
  314. }
  315. wsprintf(szBuf, TEXT("%s %s (0x%lx)\n"), lpszMsg, (LPTSTR)szErrName, sc);
  316. OleDbgPrintAlways(lpszPrefix, szBuf, 0);
  317. #endif // _DEBUG
  318. }
  319. STDAPI FnAssert(LPSTR lpstrExpr, LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine)
  320. {
  321. #ifdef _DEBUG
  322. char szOutput[1024];
  323. char szTitle[256];
  324. char szModuleName[128];
  325. char *pszModuleName;
  326. int id;
  327. DWORD tid = GetCurrentThreadId();
  328. DWORD pid = GetCurrentProcessId();
  329. wsprintfA(szOutput, "%s %s File: %s Line: %d PID: %d TID: %d\n",
  330. lpstrExpr, lpstrMsg ? lpstrMsg : "", lpstrFileName, pid, tid);
  331. OutputDebugString(szOutput);
  332. if (GetModuleFileNameA(NULL, szModuleName, 128))
  333. {
  334. pszModuleName = strrchr(szModuleName, '\\');
  335. if (!pszModuleName)
  336. {
  337. pszModuleName = szModuleName;
  338. }
  339. else
  340. {
  341. pszModuleName++;
  342. }
  343. }
  344. else
  345. {
  346. pszModuleName = "Unknown";
  347. }
  348. wsprintfA(szTitle, "Process: %s File: %s, line %u",
  349. pszModuleName, lpstrFileName, iLine);
  350. wsprintfA(szOutput, "%s %s PID.TID %d.%d",
  351. lpstrExpr, lpstrMsg ? lpstrMsg : "", pid, tid);
  352. id = MessageBoxA(NULL,
  353. szOutput,
  354. szTitle,
  355. MB_SETFOREGROUND | MB_DEFAULT_DESKTOP_ONLY |
  356. MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OKCANCEL);
  357. if (id == IDCANCEL)
  358. {
  359. DebugBreak();
  360. }
  361. #endif // _DEBUG
  362. return NOERROR;
  363. }