Leaked source code of windows server 2003
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.

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