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.

1310 lines
30 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: dbgdump.cpp
  7. //
  8. // Contents: contains APIs to dump structures (return a formatted string
  9. // of structure dumps in a coherent fashion)
  10. //
  11. // Classes:
  12. //
  13. // Functions:
  14. //
  15. // History: dd-mmm-yy Author Comment
  16. // 23-Jan-95 t-ScottH author
  17. //
  18. //--------------------------------------------------------------------------
  19. #include <le2int.h>
  20. #include <memstm.h>
  21. #include <dbgdump.h>
  22. #ifdef _DEBUG
  23. const char szDumpErrorMessage[] = "Dump Error - Out of Memory \n\0";
  24. const char szDumpBadPtr[] = "Dump Error - NULL pointer \n\0";
  25. #endif // _DEBUG
  26. //+-------------------------------------------------------------------------
  27. //
  28. // Function: DumpADVFFlags, public (_DEBUG only)
  29. //
  30. // Synopsis: returns a char array with the set flags and hex value
  31. //
  32. // Effects:
  33. //
  34. // Arguments: [dwADVF] - flags
  35. //
  36. // Requires:
  37. //
  38. // Returns: character arry of string value of flags
  39. //
  40. // Signals:
  41. //
  42. // Modifies:
  43. //
  44. // Algorithm:
  45. //
  46. // History: dd-mmm-yy Author Comment
  47. // 30-Jan-95 t-ScottH author
  48. //
  49. // Notes:
  50. //
  51. //--------------------------------------------------------------------------
  52. #ifdef _DEBUG
  53. char *DumpADVFFlags(DWORD dwAdvf)
  54. {
  55. char *pszDump;
  56. dbgstream dstrDump(100);
  57. if (dwAdvf & ADVF_NODATA)
  58. {
  59. dstrDump << "ADVF_NODATA ";
  60. }
  61. if (dwAdvf & ADVF_PRIMEFIRST)
  62. {
  63. dstrDump << "ADVF_PRIMEFIRST ";
  64. }
  65. if (dwAdvf & ADVF_ONLYONCE)
  66. {
  67. dstrDump << "ADVF_ONLYONCE ";
  68. }
  69. if (dwAdvf & ADVF_DATAONSTOP)
  70. {
  71. dstrDump << "ADVF_DATAONSTOP ";
  72. }
  73. if (dwAdvf & ADVFCACHE_NOHANDLER)
  74. {
  75. dstrDump << "ADVFCACHE_NOHANDLER ";
  76. }
  77. if (dwAdvf & ADVFCACHE_FORCEBUILTIN)
  78. {
  79. dstrDump << "ADVFCACHE_FORCEBUILTIN ";
  80. }
  81. if (dwAdvf & ADVFCACHE_ONSAVE)
  82. {
  83. dstrDump << "ADVFCACHE_ONSAVE ";
  84. }
  85. // see if there are any flags set
  86. if ( ! (( dwAdvf & ADVF_NODATA ) |
  87. ( dwAdvf & ADVF_PRIMEFIRST ) |
  88. ( dwAdvf & ADVF_ONLYONCE ) |
  89. ( dwAdvf & ADVF_DATAONSTOP ) |
  90. ( dwAdvf & ADVFCACHE_NOHANDLER ) |
  91. ( dwAdvf & ADVFCACHE_FORCEBUILTIN ) |
  92. ( dwAdvf & ADVFCACHE_ONSAVE )))
  93. {
  94. dstrDump << "No FLAGS SET! ";
  95. }
  96. // cast as void * for formatting (0x????????) with sign-extension for Sundown.
  97. dstrDump << "(" << LongToPtr(dwAdvf) << ")";
  98. pszDump = dstrDump.str();
  99. if (pszDump == NULL)
  100. {
  101. return UtDupStringA(szDumpErrorMessage);
  102. }
  103. return pszDump;
  104. }
  105. #endif // _DEBUG
  106. //+-------------------------------------------------------------------------
  107. //
  108. // Function: DumpATOM, public (_DEBUG only)
  109. //
  110. // Synopsis: returns the ATOM name using GetAtomName
  111. //
  112. // Effects:
  113. //
  114. // Arguments: [atm] - the ATOM to get name of
  115. //
  116. // Requires: GetAtomNameA API
  117. //
  118. // Returns: a pointer to character array containing
  119. //
  120. // Signals:
  121. //
  122. // Modifies:
  123. //
  124. // Algorithm:
  125. //
  126. // History: dd-mmm-yy Author Comment
  127. // 27-Jan-95 t-ScottH author
  128. //
  129. // Notes:
  130. //
  131. //--------------------------------------------------------------------------
  132. #ifdef _DEBUG
  133. #define MAX_ATOMNAME 256
  134. char *DumpATOM(ATOM atm)
  135. {
  136. UINT nResult;
  137. char *pszAtom = (char *)CoTaskMemAlloc(MAX_ATOMNAME);
  138. nResult = GetAtomNameA( atm, pszAtom, MAX_ATOMNAME);
  139. if (nResult == 0) // GetAtomName failed
  140. {
  141. // try get GlobalAtomNameA
  142. nResult = GlobalGetAtomNameA(atm, pszAtom, MAX_ATOMNAME);
  143. if (nResult == 0)
  144. {
  145. CoTaskMemFree(pszAtom);
  146. return DumpWIN32Error(GetLastError());
  147. }
  148. }
  149. return pszAtom;
  150. }
  151. #endif // _DEBUG
  152. //+-------------------------------------------------------------------------
  153. //
  154. // Function: DumpCLIPFORMAT, public (_DEBUG only)
  155. //
  156. // Synopsis: returns the CLIPFORMAT name using GetClipboardFormatName
  157. //
  158. // Effects:
  159. //
  160. // Arguments: [clipformat] - the CLIPFORMAT to get name of
  161. //
  162. // Requires: GetClipboardFormatName API
  163. //
  164. // Returns: a pointer to character array containing
  165. //
  166. // Signals:
  167. //
  168. // Modifies:
  169. //
  170. // Algorithm:
  171. //
  172. // History: dd-mmm-yy Author Comment
  173. // 27-Jan-95 t-ScottH author
  174. //
  175. // Notes:
  176. //
  177. //--------------------------------------------------------------------------
  178. #ifdef _DEBUG
  179. #define MAX_FORMATNAME 256
  180. char *DumpCLIPFORMAT(CLIPFORMAT clipformat)
  181. {
  182. int nResult;
  183. char *pszClipFormat;
  184. // we have to do predefined formats by name
  185. if ( clipformat > 0xC000 )
  186. {
  187. pszClipFormat = (char *)CoTaskMemAlloc(MAX_FORMATNAME);
  188. nResult = SSGetClipboardFormatNameA( clipformat, pszClipFormat, MAX_FORMATNAME);
  189. if (nResult == 0) // GetClipboardFormatName failed
  190. {
  191. CoTaskMemFree(pszClipFormat);
  192. return DumpWIN32Error(GetLastError());
  193. }
  194. }
  195. else
  196. {
  197. switch (clipformat)
  198. {
  199. case CF_METAFILEPICT:
  200. pszClipFormat = UtDupStringA("CF_METAFILEPICT\0");
  201. break;
  202. case CF_BITMAP:
  203. pszClipFormat = UtDupStringA("CF_BITMAP\0");
  204. break;
  205. case CF_DIB:
  206. pszClipFormat = UtDupStringA("CF_DIB\0");
  207. break;
  208. case CF_PALETTE:
  209. pszClipFormat = UtDupStringA("CF_PALETTE\0");
  210. break;
  211. case CF_TEXT:
  212. pszClipFormat = UtDupStringA("CF_TEXT\0");
  213. break;
  214. case CF_UNICODETEXT:
  215. pszClipFormat = UtDupStringA("CF_UNICODETEXT\0");
  216. break;
  217. case CF_ENHMETAFILE:
  218. pszClipFormat = UtDupStringA("CF_ENHMETAFILE\0");
  219. break;
  220. default:
  221. pszClipFormat = UtDupStringA("UNKNOWN Default Format\0");
  222. break;
  223. }
  224. }
  225. return pszClipFormat;
  226. }
  227. #endif // _DEBUG
  228. //+-------------------------------------------------------------------------
  229. //
  230. // Function: DumpCMutexSem, public (_DEBUG only)
  231. //
  232. // Synopsis: not implemented
  233. //
  234. // Effects:
  235. //
  236. // Arguments: [pMS] - pointer to a CMutexSem
  237. //
  238. // Requires:
  239. //
  240. // Returns: character array
  241. //
  242. // Signals:
  243. //
  244. // Modifies:
  245. //
  246. // Algorithm:
  247. //
  248. // History: dd-mmm-yy Author Comment
  249. // 30-Jan-95 t-ScottH author
  250. //
  251. // Notes:
  252. //
  253. //--------------------------------------------------------------------------
  254. #ifdef _DEBUG
  255. char *DumpCMutexSem(CMutexSem2 *pMS)
  256. {
  257. return UtDupStringA("Dump CMutexSem not implemented\0");
  258. }
  259. #endif // _DEBUG
  260. //+-------------------------------------------------------------------------
  261. //
  262. // Function: DumpCLSID, public (_DEBUG only)
  263. //
  264. // Synopsis: dump a CLSID into a string using StringFromCLSID and
  265. // ProgIDFromCLSID
  266. //
  267. // Effects:
  268. //
  269. // Arguments: [clsid] - pointer to a CLSID
  270. //
  271. // Requires: StringFromCLSID and ProgIDFromCLSID APIs
  272. //
  273. // Returns: character array of string (allocated by OLE)
  274. //
  275. // Signals:
  276. //
  277. // Modifies:
  278. //
  279. // Algorithm:
  280. //
  281. // History: dd-mmm-yy Author Comment
  282. // 27-Jan-95 t-ScottH author
  283. //
  284. // Notes:
  285. //
  286. //--------------------------------------------------------------------------
  287. #ifdef _DEBUG
  288. char *DumpCLSID(REFCLSID clsid)
  289. {
  290. int i;
  291. HRESULT hresult;
  292. LPOLESTR pszClsidString;
  293. LPOLESTR pszClsidID;
  294. char *pszDump;
  295. hresult = StringFromCLSID(clsid, &pszClsidString);
  296. if (hresult != S_OK)
  297. {
  298. CoTaskMemFree(pszClsidString);
  299. return DumpHRESULT(hresult);
  300. }
  301. hresult = ProgIDFromCLSID(clsid, &pszClsidID);
  302. if ((hresult != S_OK)&&(hresult != REGDB_E_CLASSNOTREG))
  303. {
  304. CoTaskMemFree(pszClsidString);
  305. CoTaskMemFree(pszClsidID);
  306. return DumpHRESULT(hresult);
  307. }
  308. pszDump = (char *)CoTaskMemAlloc(512);
  309. if (hresult != REGDB_E_CLASSNOTREG)
  310. {
  311. i = wsprintfA(pszDump, "%ls %ls\0", pszClsidString, pszClsidID);
  312. }
  313. else
  314. {
  315. i = wsprintfA(pszDump, "%ls (CLSID not in registry)\0", pszClsidString);
  316. }
  317. if (i == 0)
  318. {
  319. pszDump = UtDupStringA(szDumpErrorMessage);
  320. }
  321. CoTaskMemFree(pszClsidString);
  322. CoTaskMemFree(pszClsidID);
  323. return pszDump;
  324. }
  325. #endif // _DEBUG
  326. //+-------------------------------------------------------------------------
  327. //
  328. // Function: DumpDVAPECTFlags, public (_DEBUG only)
  329. //
  330. // Synopsis: returns a char array with the set flags and hex value
  331. //
  332. // Effects:
  333. //
  334. // Arguments: [dwAspect] - flags
  335. //
  336. // Requires:
  337. //
  338. // Returns: character arry of string value of flags
  339. //
  340. // Signals:
  341. //
  342. // Modifies:
  343. //
  344. // Algorithm:
  345. //
  346. // History: dd-mmm-yy Author Comment
  347. // 30-Jan-95 t-ScottH author
  348. //
  349. // Notes:
  350. //
  351. //--------------------------------------------------------------------------
  352. #ifdef _DEBUG
  353. char *DumpDVASPECTFlags(DWORD dwAspect)
  354. {
  355. char *pszDump;
  356. dbgstream dstrDump(100);
  357. if (dwAspect & DVASPECT_CONTENT)
  358. {
  359. dstrDump << "DVASPECT_CONTENT ";
  360. }
  361. if (dwAspect & DVASPECT_THUMBNAIL)
  362. {
  363. dstrDump << "DVASPECT_THUMBNAIL ";
  364. }
  365. if (dwAspect & DVASPECT_ICON)
  366. {
  367. dstrDump << "DVASPECT_ICON ";
  368. }
  369. if (dwAspect & DVASPECT_DOCPRINT)
  370. {
  371. dstrDump << "DVASPECT_DOCPRINT ";
  372. }
  373. if ( ! ((dwAspect & DVASPECT_CONTENT) |
  374. (dwAspect & DVASPECT_THUMBNAIL) |
  375. (dwAspect & DVASPECT_ICON) |
  376. (dwAspect & DVASPECT_DOCPRINT)))
  377. {
  378. dstrDump << "No FLAGS SET! ";
  379. }
  380. dstrDump << "(" << LongToPtr(dwAspect) << ")";
  381. pszDump = dstrDump.str();
  382. if (pszDump == NULL)
  383. {
  384. return UtDupStringA(szDumpErrorMessage);
  385. }
  386. return pszDump;
  387. }
  388. #endif // _DEBUG
  389. //+-------------------------------------------------------------------------
  390. //
  391. // Function: DumpFILETIME, public (_DEBUG only)
  392. //
  393. // Synopsis: Dumps a filetime structure
  394. //
  395. // Effects:
  396. //
  397. // Arguments: [pFT] - pointer to a FILETIME structure
  398. //
  399. // Requires:
  400. //
  401. // Returns: character array of structure dump
  402. //
  403. // Signals:
  404. //
  405. // Modifies:
  406. //
  407. // Algorithm:
  408. //
  409. // History: dd-mmm-yy Author Comment
  410. // 30-Jan-95 t-ScottH author
  411. //
  412. // Notes:
  413. //
  414. //--------------------------------------------------------------------------
  415. #ifdef _DEBUG
  416. char *DumpFILETIME(FILETIME *pFT)
  417. {
  418. char *pszDump;
  419. dbgstream dstrDump(100);
  420. if (pFT == NULL)
  421. {
  422. return UtDupStringA(szDumpBadPtr);;
  423. }
  424. dstrDump << "Low: " << pFT->dwLowDateTime;
  425. dstrDump << "\tHigh: " << pFT->dwHighDateTime;
  426. pszDump = dstrDump.str();
  427. if (pszDump == NULL)
  428. {
  429. return UtDupStringA(szDumpErrorMessage);
  430. }
  431. return pszDump;
  432. }
  433. #endif // _DEBUG
  434. //+-------------------------------------------------------------------------
  435. //
  436. // Function: DumpHRESULT
  437. //
  438. // Synopsis: Takes an HRESULT and builds a character array with a
  439. // string version of the error and a hex version
  440. //
  441. // Effects:
  442. //
  443. // Arguments: [hresult] - the error which we are looking up
  444. //
  445. // Requires:
  446. //
  447. // Returns: character array
  448. //
  449. // Signals:
  450. //
  451. // Modifies:
  452. //
  453. // Algorithm:
  454. //
  455. // History: dd-mmm-yy Author Comment
  456. // 27-Jan-95 t-ScottH author
  457. //
  458. // Notes:
  459. //
  460. //--------------------------------------------------------------------------
  461. #ifdef _DEBUG
  462. char *DumpHRESULT(HRESULT hresult)
  463. {
  464. dbgstream dstrDump(100);
  465. char *pszDump;
  466. char *pszMessage = NULL;
  467. int cMsgLen;
  468. cMsgLen = FormatMessageA(
  469. FORMAT_MESSAGE_FROM_SYSTEM |
  470. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  471. 0,
  472. hresult,
  473. MAKELANGID(0, SUBLANG_ENGLISH_US),
  474. (char *)pszMessage,
  475. 512,
  476. 0);
  477. if (cMsgLen == 0) // FormatMessage failed
  478. {
  479. delete[] pszMessage;
  480. return UtDupStringA(szDumpErrorMessage);
  481. }
  482. dstrDump << "Error Code: " << pszMessage;
  483. dstrDump << "(" << hresult << ")";
  484. pszDump = dstrDump.str();
  485. if (pszDump == NULL)
  486. {
  487. pszDump = UtDupStringA(szDumpErrorMessage);
  488. }
  489. delete[] pszMessage;
  490. return pszDump;
  491. }
  492. #endif // _DEBUG
  493. //+-------------------------------------------------------------------------
  494. //
  495. // Function: DumpMonikerDisplayName
  496. //
  497. // Synopsis: dumps a meaningful moniker name
  498. //
  499. // Effects:
  500. //
  501. // Arguments: [pMoniker] - pointer to IMoniker interface
  502. //
  503. // Requires:
  504. //
  505. // Returns: character array of display name (ANSI)
  506. //
  507. // Signals:
  508. //
  509. // Modifies:
  510. //
  511. // Algorithm:
  512. //
  513. // History: dd-mmm-yy Author Comment
  514. // 09-Feb-95 t-ScottH author
  515. //
  516. // Notes:
  517. //
  518. //--------------------------------------------------------------------------
  519. #ifdef _DEBUG
  520. char *DumpMonikerDisplayName(IMoniker *pMoniker)
  521. {
  522. int i;
  523. HRESULT hresult;
  524. LPOLESTR pszMoniker;
  525. char *pszDump;
  526. LPBC pBC;
  527. if (pMoniker == NULL)
  528. {
  529. return UtDupStringA(szDumpBadPtr);
  530. }
  531. hresult = CreateBindCtx(0, &pBC);
  532. if (hresult != S_OK)
  533. {
  534. return DumpHRESULT(hresult);
  535. }
  536. hresult = pMoniker->GetDisplayName(pBC, NULL, &pszMoniker);
  537. if (hresult != S_OK)
  538. {
  539. CoTaskMemFree(pszMoniker);
  540. return DumpHRESULT(hresult);
  541. }
  542. pszDump = (char *)CoTaskMemAlloc(512);
  543. i = wsprintfA(pszDump, "%ls \0", pszMoniker);
  544. if (i == 0)
  545. {
  546. pszDump = UtDupStringA(szDumpErrorMessage);
  547. }
  548. CoTaskMemFree(pszMoniker);
  549. return pszDump;
  550. }
  551. #endif // _DEBUG
  552. //+-------------------------------------------------------------------------
  553. //
  554. // Function: DumpWIN32Error
  555. //
  556. // Synopsis: Takes an WIN32 error and builds a character array with a
  557. // string version of the error and a hex version
  558. //
  559. // Effects:
  560. //
  561. // Arguments: [dwError] - the error which we are looking up
  562. //
  563. // Requires:
  564. //
  565. // Returns: character array
  566. //
  567. // Signals:
  568. //
  569. // Modifies:
  570. //
  571. // Algorithm:
  572. //
  573. // History: dd-mmm-yy Author Comment
  574. // 27-Jan-95 t-ScottH author
  575. //
  576. // Notes:
  577. //
  578. //--------------------------------------------------------------------------
  579. #ifdef _DEBUG
  580. char *DumpWIN32Error(DWORD dwError)
  581. {
  582. HRESULT hresult;
  583. hresult = HRESULT_FROM_WIN32(dwError);
  584. return DumpHRESULT(hresult);
  585. }
  586. #endif // _DEBUG
  587. //+-------------------------------------------------------------------------
  588. //
  589. // Function: DumpCACHELIST_ITEM, public (_DEBUG only)
  590. //
  591. // Synopsis: returns a string containing the contents of the data members
  592. //
  593. // Effects:
  594. //
  595. // Arguments: [pCLI] - a pointer to a CACHELIST_ITEM object
  596. // [ulFlag] - a flag determining the prefix of all newlines of
  597. // the out character array(default is 0 -no prefix)
  598. // [nIndentLevel] - will add an indent prefix after the other prefix
  599. // for all newlines(include those with no prefix)
  600. //
  601. // Requires:
  602. //
  603. // Returns: character array of structure dump or error (null terminated)
  604. //
  605. // Signals:
  606. //
  607. // Modifies:
  608. //
  609. // Algorithm:
  610. //
  611. // History: dd-mmm-yy Author Comment
  612. // 23-Jan-95 t-ScottH author
  613. //
  614. // Notes:
  615. //
  616. //--------------------------------------------------------------------------
  617. #ifdef _DEBUG
  618. /* char *DumpCACHELIST_ITEM(CACHELIST_ITEM *pCLI, ULONG ulFlag, int nIndentLevel)
  619. {
  620. int i;
  621. char *pszPrefix;
  622. char *pszDump;
  623. char *pszCCacheNode;
  624. dbgstream dstrPrefix;
  625. dbgstream dstrDump(1500);
  626. if (pCLI == NULL)
  627. {
  628. return UtDupStringA(szDumpBadPtr);
  629. }
  630. // determine prefix
  631. if ( ulFlag & DEB_VERBOSE )
  632. {
  633. dstrPrefix << pCLI << " _VB ";
  634. }
  635. // determine indentation prefix
  636. for (i = 0; i < nIndentLevel; i++)
  637. {
  638. dstrPrefix << DUMPTAB;
  639. }
  640. pszPrefix = dstrPrefix.str();
  641. // put data members in stream
  642. dstrDump << pszPrefix << "Cache Node ID = " << pCLI->dwCacheId << endl;
  643. if (pCLI->lpCacheNode != NULL)
  644. {
  645. pszCCacheNode = DumpCCacheNode(pCLI->lpCacheNode, ulFlag, nIndentLevel + 1);
  646. dstrDump << pszPrefix << "Cache Node:" << endl;
  647. dstrDump << pszCCacheNode;
  648. CoTaskMemFree(pszCCacheNode);
  649. }
  650. else
  651. {
  652. dstrDump << pszPrefix << "lpCacheNode = " << pCLI->lpCacheNode << endl;
  653. }
  654. // cleanup and provide pointer to character array
  655. pszDump = dstrDump.str();
  656. if (pszDump == NULL)
  657. {
  658. pszDump = UtDupStringA(szDumpErrorMessage);
  659. }
  660. CoTaskMemFree(pszPrefix);
  661. return pszDump;
  662. }
  663. */
  664. #endif // _DEBUG
  665. //+-------------------------------------------------------------------------
  666. //
  667. // Function: DumpCMapDwordDword, public (_DEBUG only)
  668. //
  669. // Synopsis: not implemented
  670. //
  671. // Effects:
  672. //
  673. // Arguments: [pMDD] - pointer to a CMapDwordDword
  674. //
  675. // Requires:
  676. //
  677. // Returns: character array
  678. //
  679. // Signals:
  680. //
  681. // Modifies:
  682. //
  683. // Algorithm:
  684. //
  685. // History: dd-mmm-yy Author Comment
  686. // 30-Jan-95 t-ScottH author
  687. //
  688. // Notes:
  689. //
  690. //--------------------------------------------------------------------------
  691. #ifdef _DEBUG
  692. char *DumpCMapDwordDword(CMapDwordDword *pMDD, ULONG ulFlag, int nIndentLevel)
  693. {
  694. return UtDupStringA(" DumpCMapDwordDword is not implemented\n");
  695. }
  696. #endif // _DEBUG
  697. //+-------------------------------------------------------------------------
  698. //
  699. // Function: DumpFORMATETC, public (_DEBUG only)
  700. //
  701. // Synopsis: returns a string containing the contents of the data members
  702. //
  703. // Effects:
  704. //
  705. // Arguments: [pFE] - a pointer to a FORMATETC object
  706. // [ulFlag] - a flag determining the prefix of all newlines of
  707. // the out character array(default is 0 -no prefix)
  708. // [nIndentLevel] - will add an indent prefix after the other prefix
  709. // for all newlines(include those with no prefix)
  710. //
  711. // Requires:
  712. //
  713. // Returns: character array of structure dump or error (null terminated)
  714. //
  715. // Signals:
  716. //
  717. // Modifies:
  718. //
  719. // Algorithm:
  720. //
  721. // History: dd-mmm-yy Author Comment
  722. // 23-Jan-95 t-ScottH author
  723. //
  724. // Notes:
  725. //
  726. //--------------------------------------------------------------------------
  727. #ifdef _DEBUG
  728. char *DumpFORMATETC(FORMATETC *pFE, ULONG ulFlag, int nIndentLevel)
  729. {
  730. int i;
  731. char *pszPrefix;
  732. char *pszDump;
  733. char *pszClipFormat;
  734. char *pszDVASPECT;
  735. dbgstream dstrPrefix;
  736. dbgstream dstrDump;
  737. if (pFE == NULL)
  738. {
  739. return UtDupStringA(szDumpBadPtr);
  740. }
  741. // determine prefix
  742. if ( ulFlag & DEB_VERBOSE )
  743. {
  744. dstrPrefix << pFE << " _VB ";
  745. }
  746. // determine indentation prefix
  747. for (i = 0; i < nIndentLevel; i++)
  748. {
  749. dstrPrefix << DUMPTAB;
  750. }
  751. pszPrefix = dstrPrefix.str();
  752. // put data members in stream
  753. pszClipFormat = DumpCLIPFORMAT(pFE->cfFormat);
  754. dstrDump << pszPrefix << "CLIPFORMAT = " << pszClipFormat << endl;
  755. CoTaskMemFree(pszClipFormat);
  756. dstrDump << pszPrefix << "pDVTARGETDEVICE = " << pFE->ptd << endl;
  757. pszDVASPECT = DumpDVASPECTFlags(pFE->dwAspect);
  758. dstrDump << pszPrefix << "Aspect Flags = " << pszDVASPECT << endl;
  759. CoTaskMemFree(pszDVASPECT);
  760. dstrDump << pszPrefix << "Tymed Flags = ";
  761. if (pFE->tymed & TYMED_HGLOBAL)
  762. {
  763. dstrDump << "TYMED_HGLOBAL ";
  764. }
  765. if (pFE->tymed & TYMED_FILE)
  766. {
  767. dstrDump << "TYMED_FILE ";
  768. }
  769. if (pFE->tymed & TYMED_ISTREAM)
  770. {
  771. dstrDump << "TYMED_ISTREAM ";
  772. }
  773. if (pFE->tymed & TYMED_ISTORAGE)
  774. {
  775. dstrDump << "TYMED_ISTORAGE ";
  776. }
  777. if (pFE->tymed & TYMED_GDI)
  778. {
  779. dstrDump << "TYMED_GDI ";
  780. }
  781. if (pFE->tymed & TYMED_MFPICT)
  782. {
  783. dstrDump << "TYMED_MFPICT ";
  784. }
  785. if (pFE->tymed & TYMED_ENHMF)
  786. {
  787. dstrDump << "TYMED_ENHMF ";
  788. }
  789. if (pFE->tymed == TYMED_NULL)
  790. {
  791. dstrDump << "TYMED_NULL ";
  792. }
  793. // if none of the flags are set there is an error
  794. if ( !( (pFE->tymed & TYMED_HGLOBAL ) |
  795. (pFE->tymed & TYMED_FILE ) |
  796. (pFE->tymed & TYMED_ISTREAM ) |
  797. (pFE->tymed & TYMED_ISTORAGE ) |
  798. (pFE->tymed & TYMED_GDI ) |
  799. (pFE->tymed & TYMED_MFPICT ) |
  800. (pFE->tymed & TYMED_ENHMF ) |
  801. (pFE->tymed == TYMED_NULL )))
  802. {
  803. dstrDump << "Error in FLAG!!!! ";
  804. }
  805. dstrDump << "(" << LongToPtr(pFE->tymed) << ")" << endl;
  806. // cleanup and provide pointer to character array
  807. pszDump = dstrDump.str();
  808. if (pszDump == NULL)
  809. {
  810. pszDump = UtDupStringA(szDumpErrorMessage);
  811. }
  812. CoTaskMemFree(pszPrefix);
  813. return pszDump;
  814. }
  815. #endif // _DEBUG
  816. //+-------------------------------------------------------------------------
  817. //
  818. // Function: DumpIOlePresObj, public (_DEBUG only)
  819. //
  820. // Synopsis: calls the IOlePresObj::Dump method, takes care of errors and
  821. // returns the zero terminated string
  822. //
  823. // Effects:
  824. //
  825. // Arguments: [pOPO] - pointer to IOlePresObj
  826. // [ulFlag] - flag determining prefix of all newlines of the
  827. // out character array (default is 0 - no prefix)
  828. // [nIndentLevel] - will add a indent prefix after the other prefix
  829. // for ALL newlines (including those with no prefix)
  830. //
  831. // Requires:
  832. //
  833. // Returns: character array of structure dump or error (null terminated)
  834. //
  835. // Signals:
  836. //
  837. // Modifies:
  838. //
  839. // Algorithm:
  840. //
  841. // History: dd-mmm-yy Author Comment
  842. // 31-Jan-95 t-ScottH author
  843. //
  844. // Notes:
  845. //
  846. //--------------------------------------------------------------------------
  847. #ifdef _DEBUG
  848. char *DumpIOlePresObj(IOlePresObj *pOPO, ULONG ulFlag, int nIndentLevel)
  849. {
  850. HRESULT hresult;
  851. char *pszDump;
  852. if (pOPO == NULL)
  853. {
  854. return UtDupStringA(szDumpBadPtr);
  855. }
  856. // defers to CMfObject, CEMfObject, CGenObject
  857. hresult = pOPO->Dump(&pszDump, ulFlag, nIndentLevel);
  858. if (hresult != NOERROR)
  859. {
  860. CoTaskMemFree(pszDump);
  861. return DumpHRESULT(hresult);
  862. }
  863. return pszDump;
  864. }
  865. #endif // _DEBUG
  866. //+-------------------------------------------------------------------------
  867. //
  868. // Function: DumpMEMSTM, public (_DEBUG only)
  869. //
  870. // Synopsis: returns a string containing the contents of the data members
  871. //
  872. // Effects:
  873. //
  874. // Arguments: [pMS] - a pointer to a MEMSTM object
  875. // [ulFlag] - a flag determining the prefix of all newlines of
  876. // the out character array(default is 0 -no prefix)
  877. // [nIndentLevel] - will add an indent prefix after the other prefix
  878. // for all newlines(include those with no prefix)
  879. //
  880. // Requires:
  881. //
  882. // Returns: character array of structure dump or error (null terminated)
  883. //
  884. // Signals:
  885. //
  886. // Modifies:
  887. //
  888. // Algorithm:
  889. //
  890. // History: dd-mmm-yy Author Comment
  891. // 23-Jan-95 t-ScottH author
  892. //
  893. // Notes:
  894. //
  895. //--------------------------------------------------------------------------
  896. #ifdef _DEBUG
  897. char *DumpMEMSTM(MEMSTM *pMS, ULONG ulFlag, int nIndentLevel)
  898. {
  899. int i;
  900. char *pszPrefix;
  901. char *pszDump;
  902. dbgstream dstrPrefix;
  903. dbgstream dstrDump;
  904. if (pMS == NULL)
  905. {
  906. return UtDupStringA(szDumpBadPtr);
  907. }
  908. // determine prefix
  909. if ( ulFlag & DEB_VERBOSE )
  910. {
  911. dstrPrefix << pMS << " _VB ";
  912. }
  913. // determine indentation prefix
  914. for (i = 0; i < nIndentLevel; i++)
  915. {
  916. dstrPrefix << DUMPTAB;
  917. }
  918. pszPrefix = dstrPrefix.str();
  919. // put data members in stream
  920. dstrDump << pszPrefix << "Size of Global Memory = " << pMS->cb << endl;
  921. dstrDump << pszPrefix << "References = " << pMS->cRef << endl;
  922. dstrDump << pszPrefix << "hGlobal = " << pMS->hGlobal << endl;
  923. dstrDump << pszPrefix << "DeleteOnRelease? = ";
  924. if (pMS->fDeleteOnRelease == TRUE)
  925. {
  926. dstrDump << "TRUE" << endl;
  927. }
  928. else
  929. {
  930. dstrDump << "FALSE" << endl;
  931. }
  932. // cleanup and provide pointer to character array
  933. pszDump = dstrDump.str();
  934. if (pszDump == NULL)
  935. {
  936. pszDump = UtDupStringA(szDumpErrorMessage);
  937. }
  938. CoTaskMemFree(pszPrefix);
  939. return pszDump;
  940. }
  941. #endif // _DEBUG
  942. //+-------------------------------------------------------------------------
  943. //
  944. // Function: DumpSTATDATA, public (_DEBUG only)
  945. //
  946. // Synopsis: returns a string containing the contents of the data members
  947. //
  948. // Effects:
  949. //
  950. // Arguments: [pSD] - a pointer to a STATDATA object
  951. // [ulFlag] - a flag determining the prefix of all newlines of
  952. // the out character array(default is 0 -no prefix)
  953. // [nIndentLevel] - will add an indent prefix after the other prefix
  954. // for all newlines(include those with no prefix)
  955. //
  956. // Requires:
  957. //
  958. // Returns: character array of structure dump or error (null terminated)
  959. //
  960. // Signals:
  961. //
  962. // Modifies:
  963. //
  964. // Algorithm:
  965. //
  966. // History: dd-mmm-yy Author Comment
  967. // 23-Jan-95 t-ScottH author
  968. //
  969. // Notes:
  970. //
  971. //--------------------------------------------------------------------------
  972. #ifdef _DEBUG
  973. char *DumpSTATDATA(STATDATA *pSD, ULONG ulFlag, int nIndentLevel)
  974. {
  975. int i;
  976. char *pszPrefix;
  977. char *pszDump;
  978. char *pszFORMATETC;
  979. char *pszADVF;
  980. dbgstream dstrPrefix;
  981. dbgstream dstrDump(500);
  982. if (pSD == NULL)
  983. {
  984. return UtDupStringA(szDumpBadPtr);
  985. }
  986. // determine prefix
  987. if ( ulFlag & DEB_VERBOSE )
  988. {
  989. dstrPrefix << pSD << " _VB ";
  990. }
  991. // determine indentation prefix
  992. for (i = 0; i < nIndentLevel; i++)
  993. {
  994. dstrPrefix << DUMPTAB;
  995. }
  996. pszPrefix = dstrPrefix.str();
  997. // put data members in stream
  998. pszFORMATETC = DumpFORMATETC( &(pSD->formatetc), ulFlag, nIndentLevel + 1);
  999. dstrDump << pszPrefix << "FORMATETC:" << endl;
  1000. dstrDump << pszFORMATETC;
  1001. CoTaskMemFree(pszFORMATETC);
  1002. pszADVF = DumpADVFFlags( pSD->advf );
  1003. dstrDump << pszPrefix << "Advise flag = " << pszADVF << endl;
  1004. CoTaskMemFree(pszADVF);
  1005. dstrDump << pszPrefix << "pIAdviseSink = " << pSD->pAdvSink << endl;
  1006. dstrDump << pszPrefix << "Connection ID = " << pSD->dwConnection << endl;
  1007. // cleanup and provide pointer to character array
  1008. pszDump = dstrDump.str();
  1009. if (pszDump == NULL)
  1010. {
  1011. pszDump = UtDupStringA(szDumpErrorMessage);
  1012. }
  1013. CoTaskMemFree(pszPrefix);
  1014. return pszDump;
  1015. }
  1016. #endif // _DEBUG
  1017. //+-------------------------------------------------------------------------
  1018. //
  1019. // Function: DumpSTGMEDIUM, public (_DEBUG only)
  1020. //
  1021. // Synopsis: returns a string containing the contents of the data members
  1022. //
  1023. // Effects:
  1024. //
  1025. // Arguments: [pFE] - a pointer to a STGMEDIUM object
  1026. // [ulFlag] - a flag determining the prefix of all newlines of
  1027. // the out character array(default is 0 -no prefix)
  1028. // [nIndentLevel] - will add an indent prefix after the other prefix
  1029. // for all newlines(include those with no prefix)
  1030. //
  1031. // Requires:
  1032. //
  1033. // Returns: character array of structure dump or error (null terminated)
  1034. //
  1035. // Signals:
  1036. //
  1037. // Modifies:
  1038. //
  1039. // Algorithm:
  1040. //
  1041. // History: dd-mmm-yy Author Comment
  1042. // 23-Jan-95 t-ScottH author
  1043. //
  1044. // Notes:
  1045. //
  1046. //--------------------------------------------------------------------------
  1047. #ifdef _DEBUG
  1048. char *DumpSTGMEDIUM(STGMEDIUM *pSM, ULONG ulFlag, int nIndentLevel)
  1049. {
  1050. int i;
  1051. char *pszPrefix;
  1052. char *pszDump;
  1053. dbgstream dstrPrefix;
  1054. dbgstream dstrDump;
  1055. if (pSM == NULL)
  1056. {
  1057. return UtDupStringA(szDumpBadPtr);
  1058. }
  1059. // determine prefix
  1060. if ( ulFlag & DEB_VERBOSE )
  1061. {
  1062. dstrPrefix << pSM << " _VB ";
  1063. }
  1064. // determine indentation prefix
  1065. for (i = 0; i < nIndentLevel; i++)
  1066. {
  1067. dstrPrefix << DUMPTAB;
  1068. }
  1069. pszPrefix = dstrPrefix.str();
  1070. // put data members in stream
  1071. dstrDump << pszPrefix << "Tymed Flags = ";
  1072. if (pSM->tymed & TYMED_HGLOBAL)
  1073. {
  1074. dstrDump << "TYMED_HGLOBAL ";
  1075. }
  1076. if (pSM->tymed & TYMED_FILE)
  1077. {
  1078. dstrDump << "TYMED_FILE ";
  1079. }
  1080. if (pSM->tymed & TYMED_ISTREAM)
  1081. {
  1082. dstrDump << "TYMED_ISTREAM ";
  1083. }
  1084. if (pSM->tymed & TYMED_ISTORAGE)
  1085. {
  1086. dstrDump << "TYMED_ISTORAGE ";
  1087. }
  1088. if (pSM->tymed & TYMED_GDI)
  1089. {
  1090. dstrDump << "TYMED_GDI ";
  1091. }
  1092. if (pSM->tymed & TYMED_MFPICT)
  1093. {
  1094. dstrDump << "TYMED_MFPICT ";
  1095. }
  1096. if (pSM->tymed & TYMED_ENHMF)
  1097. {
  1098. dstrDump << "TYMED_ENHMF ";
  1099. }
  1100. if (pSM->tymed == TYMED_NULL)
  1101. {
  1102. dstrDump << "TYMED_NULL ";
  1103. }
  1104. // if none of the flags are set there is an error
  1105. if ( !( (pSM->tymed & TYMED_HGLOBAL ) |
  1106. (pSM->tymed & TYMED_FILE ) |
  1107. (pSM->tymed & TYMED_ISTREAM ) |
  1108. (pSM->tymed & TYMED_ISTORAGE ) |
  1109. (pSM->tymed & TYMED_GDI ) |
  1110. (pSM->tymed & TYMED_MFPICT ) |
  1111. (pSM->tymed & TYMED_ENHMF ) |
  1112. (pSM->tymed == TYMED_NULL )))
  1113. {
  1114. dstrDump << "Error in FLAG!!!! ";
  1115. }
  1116. dstrDump << "(" << LongToPtr(pSM->tymed) << ")" << endl;
  1117. dstrDump << pszPrefix << "Union (handle or pointer) = " << pSM->hBitmap << endl;
  1118. dstrDump << pszPrefix << "pIUnknown for Release = " << pSM->pUnkForRelease << endl;
  1119. // cleanup and provide pointer to character array
  1120. pszDump = dstrDump.str();
  1121. if (pszDump == NULL)
  1122. {
  1123. pszDump = UtDupStringA(szDumpErrorMessage);
  1124. }
  1125. CoTaskMemFree(pszPrefix);
  1126. return pszDump;
  1127. }
  1128. #endif // _DEBUG