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.

954 lines
31 KiB

  1. /***********************************************************************
  2. *
  3. * DBGUTIL.C
  4. *
  5. * Debug utility functions
  6. *
  7. * Copyright 1992 - 1996 Microsoft Corporation. All Rights Reserved.
  8. *
  9. * Revision History:
  10. *
  11. * When Who What
  12. * -------- ------------------ ---------------------------------------
  13. * 11.13.95 Bruce Kelley Created
  14. *
  15. ***********************************************************************/
  16. #ifdef DEBUG
  17. #include <windows.h>
  18. //#include <mapix.h>
  19. #include <wab.h>
  20. #include <wabdbg.h>
  21. #include <shlwapi.h>
  22. #include "dbgutil.h"
  23. #define _WAB_DBGUTIL_C
  24. #ifndef ARRAYSIZE
  25. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  26. #endif
  27. PUCHAR PropTagName(ULONG ulPropTag);
  28. const TCHAR szNULL[] = "";
  29. extern SCODE WABFreeBuffer(LPVOID lpBuffer);
  30. VOID FAR CDECL _DebugTrace(LPSTR lpszFmt, ...);
  31. /***************************************************************************
  32. Name : FreeBufferAndNull
  33. Purpose : Frees a MAPI buffer and NULLs the pointer
  34. Parameters: lppv = pointer to buffer pointer to free
  35. Returns : void
  36. Comment : Remember to pass in the pointer to the pointer. The
  37. compiler is not smart enough to tell if you are doing this
  38. right or not, but you will know at runtime!
  39. BUGBUG: Make this fastcall!
  40. ***************************************************************************/
  41. void __fastcall FreeBufferAndNull(BOOL fMAPI, LPVOID * lppv) {
  42. if (lppv) {
  43. if (*lppv) {
  44. SCODE sc;
  45. if (fMAPI) {
  46. #ifdef OLD_STUFF
  47. if (sc = MAPIFreeBuffer(*lppv)) {
  48. DebugTrace("MAPIFreeBuffer(%x) -> 0x%08x\n", *lppv, sc);
  49. }
  50. #endif // OLD_STUFF
  51. } else {
  52. if (sc = WABFreeBuffer(*lppv)) {
  53. DebugTrace("WABFreeBuffer(%x) -> 0x%08x\n", *lppv, sc);
  54. }
  55. }
  56. *lppv = NULL;
  57. }
  58. }
  59. }
  60. /***************************************************************************
  61. Name : ReleaseAndNull
  62. Purpose : Releases an object and NULLs the pointer
  63. Parameters: lppv = pointer to pointer to object to release
  64. Returns : void
  65. Comment : Remember to pass in the pointer to the pointer. The
  66. compiler is not smart enough to tell if you are doing this
  67. right or not, but you will know at runtime!
  68. BUGBUG: Make this fastcall!
  69. ***************************************************************************/
  70. void __fastcall ReleaseAndNull(LPVOID * lppv) {
  71. LPUNKNOWN * lppunk = (LPUNKNOWN *)lppv;
  72. if (lppunk) {
  73. if (*lppunk) {
  74. HRESULT hResult;
  75. if (hResult = (*lppunk)->lpVtbl->Release(*lppunk)) {
  76. DebugTrace("Release(%x) -> 0x%08x\n", *lppunk, GetScode(hResult));
  77. }
  78. *lppunk = NULL;
  79. }
  80. }
  81. }
  82. /***************************************************************************
  83. Name : PropTypeString
  84. Purpose : Map a proptype to a string
  85. Parameters: ulPropType = property type to map
  86. Returns : string pointer to name of prop type
  87. Comment :
  88. ***************************************************************************/
  89. LPTSTR PropTypeString(ULONG ulPropType) {
  90. switch (ulPropType) {
  91. case PT_UNSPECIFIED:
  92. return("PT_UNSPECIFIED");
  93. case PT_NULL:
  94. return("PT_NULL ");
  95. case PT_I2:
  96. return("PT_I2 ");
  97. case PT_LONG:
  98. return("PT_LONG ");
  99. case PT_R4:
  100. return("PT_R4 ");
  101. case PT_DOUBLE:
  102. return("PT_DOUBLE ");
  103. case PT_CURRENCY:
  104. return("PT_CURRENCY ");
  105. case PT_APPTIME:
  106. return("PT_APPTIME ");
  107. case PT_ERROR:
  108. return("PT_ERROR ");
  109. case PT_BOOLEAN:
  110. return("PT_BOOLEAN ");
  111. case PT_OBJECT:
  112. return("PT_OBJECT ");
  113. case PT_I8:
  114. return("PT_I8 ");
  115. case PT_STRING8:
  116. return("PT_STRING8 ");
  117. case PT_UNICODE:
  118. return("PT_UNICODE ");
  119. case PT_SYSTIME:
  120. return("PT_SYSTIME ");
  121. case PT_CLSID:
  122. return("PT_CLSID ");
  123. case PT_BINARY:
  124. return("PT_BINARY ");
  125. case PT_MV_I2:
  126. return("PT_MV_I2 ");
  127. case PT_MV_LONG:
  128. return("PT_MV_LONG ");
  129. case PT_MV_R4:
  130. return("PT_MV_R4 ");
  131. case PT_MV_DOUBLE:
  132. return("PT_MV_DOUBLE ");
  133. case PT_MV_CURRENCY:
  134. return("PT_MV_CURRENCY");
  135. case PT_MV_APPTIME:
  136. return("PT_MV_APPTIME ");
  137. case PT_MV_SYSTIME:
  138. return("PT_MV_SYSTIME ");
  139. case PT_MV_STRING8:
  140. return("PT_MV_STRING8 ");
  141. case PT_MV_BINARY:
  142. return("PT_MV_BINARY ");
  143. case PT_MV_UNICODE:
  144. return("PT_MV_UNICODE ");
  145. case PT_MV_CLSID:
  146. return("PT_MV_CLSID ");
  147. case PT_MV_I8:
  148. return("PT_MV_I8 ");
  149. default:
  150. return(" <unknown> ");
  151. }
  152. }
  153. /***************************************************************************
  154. Name : TraceMVPStrings
  155. Purpose : Debug trace a multivalued string property value
  156. Parameters: lpszCaption = caption string
  157. PropValue = property value to dump
  158. Returns : none
  159. Comment :
  160. ***************************************************************************/
  161. void _TraceMVPStrings(LPTSTR lpszCaption, SPropValue PropValue) {
  162. ULONG i;
  163. DebugTrace("-----------------------------------------------------\n");
  164. DebugTrace("%s", lpszCaption);
  165. switch (PROP_TYPE(PropValue.ulPropTag)) {
  166. case PT_ERROR:
  167. DebugTrace("Error value 0x%08x\n", PropValue.Value.err);
  168. break;
  169. case PT_MV_TSTRING:
  170. DebugTrace("%u values\n", PropValue.Value.MVSZ.cValues);
  171. if (PropValue.Value.MVSZ.cValues) {
  172. DebugTrace("- - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
  173. for (i = 0; i < PropValue.Value.MVSZ.cValues; i++) {
  174. DebugTrace("%u: \"%s\"\n", i, PropValue.Value.MVSZ.LPPSZ[i]);
  175. }
  176. DebugTrace("- - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
  177. }
  178. break;
  179. default:
  180. DebugTrace("TraceMVPStrings got incorrect property type %u for tag %x\n",
  181. PROP_TYPE(PropValue.ulPropTag), PropValue.ulPropTag);
  182. break;
  183. }
  184. }
  185. /***************************************************************************
  186. Name : DebugBinary
  187. Purpose : Debug dump an array of bytes
  188. Parameters: cb = number of bytes to dump
  189. lpb -> bytes to dump
  190. Returns : none
  191. Comment :
  192. ***************************************************************************/
  193. #define DEBUG_NUM_BINARY_LINES 2
  194. VOID DebugBinary(UINT cb, LPBYTE lpb) {
  195. UINT cbLines = 0;
  196. #if (DEBUG_NUM_BINARY_LINES != 0)
  197. UINT cbi;
  198. while (cb && cbLines < DEBUG_NUM_BINARY_LINES) {
  199. cbi = min(cb, 16);
  200. cb -= cbi;
  201. switch (cbi) {
  202. case 16:
  203. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  204. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  205. lpb[8], lpb[9], lpb[10], lpb[11], lpb[12], lpb[13], lpb[14],
  206. lpb[15]);
  207. break;
  208. case 1:
  209. DebugTrace("%02x\n", lpb[0]);
  210. break;
  211. case 2:
  212. DebugTrace("%02x %02x\n", lpb[0], lpb[1]);
  213. break;
  214. case 3:
  215. DebugTrace("%02x %02x %02x\n", lpb[0], lpb[1], lpb[2]);
  216. break;
  217. case 4:
  218. DebugTrace("%02x %02x %02x %02x\n", lpb[0], lpb[1], lpb[2], lpb[3]);
  219. break;
  220. case 5:
  221. DebugTrace("%02x %02x %02x %02x %02x\n", lpb[0], lpb[1], lpb[2], lpb[3],
  222. lpb[4]);
  223. break;
  224. case 6:
  225. DebugTrace("%02x %02x %02x %02x %02x %02x\n",
  226. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5]);
  227. break;
  228. case 7:
  229. DebugTrace("%02x %02x %02x %02x %02x %02x %02x\n",
  230. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6]);
  231. break;
  232. case 8:
  233. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x\n",
  234. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7]);
  235. break;
  236. case 9:
  237. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  238. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  239. lpb[8]);
  240. break;
  241. case 10:
  242. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  243. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  244. lpb[8], lpb[9]);
  245. break;
  246. case 11:
  247. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  248. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  249. lpb[8], lpb[9], lpb[10]);
  250. break;
  251. case 12:
  252. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  253. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  254. lpb[8], lpb[9], lpb[10], lpb[11]);
  255. break;
  256. case 13:
  257. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  258. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  259. lpb[8], lpb[9], lpb[10], lpb[11], lpb[12]);
  260. break;
  261. case 14:
  262. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  263. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  264. lpb[8], lpb[9], lpb[10], lpb[11], lpb[12], lpb[13]);
  265. break;
  266. case 15:
  267. DebugTrace("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  268. lpb[0], lpb[1], lpb[2], lpb[3], lpb[4], lpb[5], lpb[6], lpb[7],
  269. lpb[8], lpb[9], lpb[10], lpb[11], lpb[12], lpb[13], lpb[14]);
  270. break;
  271. }
  272. lpb += cbi;
  273. cbLines++;
  274. }
  275. if (cb) {
  276. DebugTrace("<etc.>"); //
  277. }
  278. #endif
  279. }
  280. #define RETURN_PROP_CASE(pt) case PROP_ID(pt): return(#pt)
  281. /***************************************************************************
  282. Name : PropTagName
  283. Purpose : Associate a name with a property tag
  284. Parameters: ulPropTag = property tag
  285. Returns : none
  286. Comment : Add new Property ID's as they become known
  287. ***************************************************************************/
  288. PUCHAR PropTagName(ULONG ulPropTag) {
  289. static UCHAR szPropTag[35]; // see string on default
  290. switch (PROP_ID(ulPropTag)) {
  291. RETURN_PROP_CASE(PR_INITIALS);
  292. RETURN_PROP_CASE(PR_SURNAME);
  293. RETURN_PROP_CASE(PR_TITLE);
  294. RETURN_PROP_CASE(PR_TELEX_NUMBER);
  295. RETURN_PROP_CASE(PR_GIVEN_NAME);
  296. RETURN_PROP_CASE(PR_PRIMARY_TELEPHONE_NUMBER);
  297. RETURN_PROP_CASE(PR_PRIMARY_FAX_NUMBER);
  298. RETURN_PROP_CASE(PR_POSTAL_CODE);
  299. RETURN_PROP_CASE(PR_POSTAL_ADDRESS);
  300. RETURN_PROP_CASE(PR_POST_OFFICE_BOX);
  301. RETURN_PROP_CASE(PR_PAGER_TELEPHONE_NUMBER);
  302. RETURN_PROP_CASE(PR_OTHER_TELEPHONE_NUMBER);
  303. RETURN_PROP_CASE(PR_ORGANIZATIONAL_ID_NUMBER);
  304. RETURN_PROP_CASE(PR_OFFICE_LOCATION);
  305. RETURN_PROP_CASE(PR_LOCATION);
  306. RETURN_PROP_CASE(PR_LOCALITY);
  307. RETURN_PROP_CASE(PR_ISDN_NUMBER);
  308. RETURN_PROP_CASE(PR_GOVERNMENT_ID_NUMBER);
  309. RETURN_PROP_CASE(PR_GENERATION);
  310. RETURN_PROP_CASE(PR_DEPARTMENT_NAME);
  311. RETURN_PROP_CASE(PR_COUNTRY);
  312. RETURN_PROP_CASE(PR_COMPANY_NAME);
  313. RETURN_PROP_CASE(PR_COMMENT);
  314. RETURN_PROP_CASE(PR_CELLULAR_TELEPHONE_NUMBER);
  315. RETURN_PROP_CASE(PR_CAR_TELEPHONE_NUMBER);
  316. RETURN_PROP_CASE(PR_CALLBACK_TELEPHONE_NUMBER);
  317. RETURN_PROP_CASE(PR_BUSINESS2_TELEPHONE_NUMBER);
  318. RETURN_PROP_CASE(PR_BUSINESS_TELEPHONE_NUMBER);
  319. RETURN_PROP_CASE(PR_BUSINESS_FAX_NUMBER);
  320. RETURN_PROP_CASE(PR_ASSISTANT_TELEPHONE_NUMBER);
  321. RETURN_PROP_CASE(PR_ASSISTANT);
  322. RETURN_PROP_CASE(PR_ACCOUNT);
  323. RETURN_PROP_CASE(PR_TEMPLATEID);
  324. RETURN_PROP_CASE(PR_DETAILS_TABLE);
  325. RETURN_PROP_CASE(PR_SEARCH_KEY);
  326. RETURN_PROP_CASE(PR_LAST_MODIFICATION_TIME);
  327. RETURN_PROP_CASE(PR_CREATION_TIME);
  328. RETURN_PROP_CASE(PR_ENTRYID);
  329. RETURN_PROP_CASE(PR_RECORD_KEY);
  330. RETURN_PROP_CASE(PR_MAPPING_SIGNATURE);
  331. RETURN_PROP_CASE(PR_OBJECT_TYPE);
  332. RETURN_PROP_CASE(PR_ROWID);
  333. RETURN_PROP_CASE(PR_ADDRTYPE);
  334. RETURN_PROP_CASE(PR_DISPLAY_NAME);
  335. RETURN_PROP_CASE(PR_EMAIL_ADDRESS);
  336. RETURN_PROP_CASE(PR_DEPTH);
  337. RETURN_PROP_CASE(PR_ROW_TYPE);
  338. RETURN_PROP_CASE(PR_RADIO_TELEPHONE_NUMBER);
  339. RETURN_PROP_CASE(PR_HOME_TELEPHONE_NUMBER);
  340. RETURN_PROP_CASE(PR_INSTANCE_KEY);
  341. RETURN_PROP_CASE(PR_DISPLAY_TYPE);
  342. RETURN_PROP_CASE(PR_RECIPIENT_TYPE);
  343. RETURN_PROP_CASE(PR_CONTAINER_FLAGS);
  344. RETURN_PROP_CASE(PR_DEF_CREATE_DL);
  345. RETURN_PROP_CASE(PR_DEF_CREATE_MAILUSER);
  346. RETURN_PROP_CASE(PR_CONTACT_ADDRTYPES);
  347. RETURN_PROP_CASE(PR_CONTACT_DEFAULT_ADDRESS_INDEX);
  348. RETURN_PROP_CASE(PR_CONTACT_EMAIL_ADDRESSES);
  349. RETURN_PROP_CASE(PR_HOME_ADDRESS_CITY);
  350. RETURN_PROP_CASE(PR_HOME_ADDRESS_COUNTRY);
  351. RETURN_PROP_CASE(PR_HOME_ADDRESS_POSTAL_CODE);
  352. RETURN_PROP_CASE(PR_HOME_ADDRESS_STATE_OR_PROVINCE);
  353. RETURN_PROP_CASE(PR_HOME_ADDRESS_STREET);
  354. RETURN_PROP_CASE(PR_HOME_ADDRESS_POST_OFFICE_BOX);
  355. RETURN_PROP_CASE(PR_MIDDLE_NAME);
  356. RETURN_PROP_CASE(PR_NICKNAME);
  357. RETURN_PROP_CASE(PR_PERSONAL_HOME_PAGE);
  358. RETURN_PROP_CASE(PR_BUSINESS_HOME_PAGE);
  359. RETURN_PROP_CASE(PR_MHS_COMMON_NAME);
  360. RETURN_PROP_CASE(PR_SEND_RICH_INFO);
  361. RETURN_PROP_CASE(PR_TRANSMITABLE_DISPLAY_NAME);
  362. default:
  363. wnsprintf(szPropTag, ARRAYSIZE(szPropTag), "Unknown property tag 0x%x",
  364. PROP_ID(ulPropTag));
  365. return(szPropTag);
  366. }
  367. }
  368. /***************************************************************************
  369. Name : DebugPropTagArray
  370. Purpose : Displays MAPI property tags from a counted array
  371. Parameters: lpPropArray -> property array
  372. pszObject -> object string (ie "Message", "Recipient", etc)
  373. Returns : none
  374. Comment :
  375. ***************************************************************************/
  376. void _DebugPropTagArray(LPSPropTagArray lpPropArray, PUCHAR pszObject) {
  377. DWORD i;
  378. PUCHAR lpType;
  379. if (lpPropArray == NULL) {
  380. DebugTrace("Empty %s property tag array.\n", pszObject ? pszObject : szNULL);
  381. return;
  382. }
  383. DebugTrace("=======================================\n");
  384. DebugTrace("+ Enumerating %u %s property tags:\n", lpPropArray->cValues,
  385. pszObject ? pszObject : szNULL);
  386. for (i = 0; i < lpPropArray->cValues ; i++) {
  387. DebugTrace("---------------------------------------\n");
  388. #if FALSE
  389. DebugTrace("PropTag:0x%08x, ID:0x%04x, PT:0x%04x\n",
  390. lpPropArray->aulPropTag[i],
  391. lpPropArray->aulPropTag[i] >> 16,
  392. lpPropArray->aulPropTag[i] & 0xffff);
  393. #endif
  394. switch (lpPropArray->aulPropTag[i] & 0xffff) {
  395. case PT_STRING8:
  396. lpType = "STRING8";
  397. break;
  398. case PT_LONG:
  399. lpType = "LONG";
  400. break;
  401. case PT_I2:
  402. lpType = "I2";
  403. break;
  404. case PT_ERROR:
  405. lpType = "ERROR";
  406. break;
  407. case PT_BOOLEAN:
  408. lpType = "BOOLEAN";
  409. break;
  410. case PT_R4:
  411. lpType = "R4";
  412. break;
  413. case PT_DOUBLE:
  414. lpType = "DOUBLE";
  415. break;
  416. case PT_CURRENCY:
  417. lpType = "CURRENCY";
  418. break;
  419. case PT_APPTIME:
  420. lpType = "APPTIME";
  421. break;
  422. case PT_SYSTIME:
  423. lpType = "SYSTIME";
  424. break;
  425. case PT_UNICODE:
  426. lpType = "UNICODE";
  427. break;
  428. case PT_CLSID:
  429. lpType = "CLSID";
  430. break;
  431. case PT_BINARY:
  432. lpType = "BINARY";
  433. break;
  434. case PT_I8:
  435. lpType = "PT_I8";
  436. break;
  437. case PT_MV_I2:
  438. lpType = "MV_I2";
  439. break;
  440. case PT_MV_LONG:
  441. lpType = "MV_LONG";
  442. break;
  443. case PT_MV_R4:
  444. lpType = "MV_R4";
  445. break;
  446. case PT_MV_DOUBLE:
  447. lpType = "MV_DOUBLE";
  448. break;
  449. case PT_MV_CURRENCY:
  450. lpType = "MV_CURRENCY";
  451. break;
  452. case PT_MV_APPTIME:
  453. lpType = "MV_APPTIME";
  454. break;
  455. case PT_MV_SYSTIME:
  456. lpType = "MV_SYSTIME";
  457. break;
  458. case PT_MV_BINARY:
  459. lpType = "MV_BINARY";
  460. break;
  461. case PT_MV_STRING8:
  462. lpType = "MV_STRING8";
  463. break;
  464. case PT_MV_UNICODE:
  465. lpType = "MV_UNICODE";
  466. break;
  467. case PT_MV_CLSID:
  468. lpType = "MV_CLSID";
  469. break;
  470. case PT_MV_I8:
  471. lpType = "MV_I8";
  472. break;
  473. case PT_NULL:
  474. lpType = "NULL";
  475. break;
  476. case PT_OBJECT:
  477. lpType = "OBJECT";
  478. break;
  479. default:
  480. DebugTrace("<Unknown Property Type>");
  481. break;
  482. }
  483. DebugTrace("%s\t%s\n", PropTagName(lpPropArray->aulPropTag[i]), lpType);
  484. }
  485. }
  486. /***************************************************************************
  487. Name : DebugProperties
  488. Purpose : Displays MAPI properties in a property list
  489. Parameters: lpProps -> property list
  490. cProps = count of properties
  491. pszObject -> object string (ie "Message", "Recipient", etc)
  492. Returns : none
  493. Comment : Add new Property ID's as they become known
  494. ***************************************************************************/
  495. void _DebugProperties(LPSPropValue lpProps, DWORD cProps, PUCHAR pszObject) {
  496. DWORD i, j;
  497. DebugTrace("=======================================\n");
  498. DebugTrace("+ Enumerating %u %s properties:\n", cProps,
  499. pszObject ? pszObject : szNULL);
  500. for (i = 0; i < cProps ; i++) {
  501. DebugTrace("---------------------------------------\n");
  502. #if FALSE
  503. DebugTrace("PropTag:0x%08x, ID:0x%04x, PT:0x%04x\n",
  504. lpProps[i].ulPropTag,
  505. lpProps[i].ulPropTag >> 16,
  506. lpProps[i].ulPropTag & 0xffff);
  507. #endif
  508. DebugTrace("%s\n", PropTagName(lpProps[i].ulPropTag));
  509. switch (lpProps[i].ulPropTag & 0xffff) {
  510. case PT_STRING8:
  511. if (lstrlen(lpProps[i].Value.lpszA) < 1024) {
  512. DebugTrace("STRING8 Value:\"%s\"\n", lpProps[i].Value.lpszA);
  513. } else {
  514. DebugTrace("STRING8 Value is too long to display\n");
  515. }
  516. break;
  517. case PT_LONG:
  518. DebugTrace("LONG Value:%u\n", lpProps[i].Value.l);
  519. break;
  520. case PT_I2:
  521. DebugTrace("I2 Value:%u\n", lpProps[i].Value.i);
  522. break;
  523. case PT_ERROR:
  524. DebugTrace("ERROR Value: 0x%08x\n", lpProps[i].Value.err);
  525. break;
  526. case PT_BOOLEAN:
  527. DebugTrace("BOOLEAN Value:%s\n", lpProps[i].Value.b ?
  528. "TRUE" : "FALSE");
  529. break;
  530. case PT_R4:
  531. DebugTrace("R4 Value\n");
  532. break;
  533. case PT_DOUBLE:
  534. DebugTrace("DOUBLE Value\n");
  535. break;
  536. case PT_CURRENCY:
  537. DebugTrace("CURRENCY Value\n");
  538. break;
  539. case PT_APPTIME:
  540. DebugTrace("APPTIME Value\n");
  541. break;
  542. case PT_SYSTIME:
  543. // DebugTime(lpProps[i].Value.ft, "SYSTIME Value:%s\n");
  544. break;
  545. case PT_UNICODE:
  546. DebugTrace("UNICODE Value\n");
  547. break;
  548. case PT_CLSID:
  549. DebugTrace("CLSID Value\n");
  550. break;
  551. case PT_BINARY:
  552. DebugTrace("BINARY Value %u bytes:\n", lpProps[i].Value.bin.cb);
  553. DebugBinary(lpProps[i].Value.bin.cb, lpProps[i].Value.bin.lpb);
  554. break;
  555. case PT_I8:
  556. DebugTrace("LARGE_INTEGER Value\n");
  557. break;
  558. case PT_MV_I2:
  559. DebugTrace("MV_I2 Value\n");
  560. break;
  561. case PT_MV_LONG:
  562. DebugTrace("MV_LONG Value\n");
  563. break;
  564. case PT_MV_R4:
  565. DebugTrace("MV_R4 Value\n");
  566. break;
  567. case PT_MV_DOUBLE:
  568. DebugTrace("MV_DOUBLE Value\n");
  569. break;
  570. case PT_MV_CURRENCY:
  571. DebugTrace("MV_CURRENCY Value\n");
  572. break;
  573. case PT_MV_APPTIME:
  574. DebugTrace("MV_APPTIME Value\n");
  575. break;
  576. case PT_MV_SYSTIME:
  577. DebugTrace("MV_SYSTIME Value\n");
  578. break;
  579. case PT_MV_BINARY:
  580. DebugTrace("MV_BINARY with %u values\n", lpProps[i].Value.MVbin.cValues);
  581. for (j = 0; j < lpProps[i].Value.MVbin.cValues; j++) {
  582. DebugTrace("BINARY Value %u: %u bytes\n", j, lpProps[i].Value.MVbin.lpbin[j].cb);
  583. DebugBinary(lpProps[i].Value.MVbin.lpbin[j].cb, lpProps[i].Value.MVbin.lpbin[j].lpb);
  584. }
  585. break;
  586. case PT_MV_STRING8:
  587. DebugTrace("MV_STRING8 with %u values\n", lpProps[i].Value.MVszA.cValues);
  588. for (j = 0; j < lpProps[i].Value.MVszA.cValues; j++) {
  589. if (lstrlen(lpProps[i].Value.MVszA.lppszA[j]) < 1024) {
  590. DebugTrace("STRING8 Value:\"%s\"\n", lpProps[i].Value.MVszA.lppszA[j]);
  591. } else {
  592. DebugTrace("STRING8 Value is too long to display\n");
  593. }
  594. }
  595. break;
  596. case PT_MV_UNICODE:
  597. DebugTrace("MV_UNICODE Value\n");
  598. break;
  599. case PT_MV_CLSID:
  600. DebugTrace("MV_CLSID Value\n");
  601. break;
  602. case PT_MV_I8:
  603. DebugTrace("MV_I8 Value\n");
  604. break;
  605. case PT_NULL:
  606. DebugTrace("NULL Value\n");
  607. break;
  608. case PT_OBJECT:
  609. DebugTrace("OBJECT Value\n");
  610. break;
  611. default:
  612. DebugTrace("Unknown Property Type\n");
  613. break;
  614. }
  615. }
  616. }
  617. /***************************************************************************
  618. Name : DebugADRLIST
  619. Purpose : Displays structure of an ADRLIST including properties
  620. Parameters: lpAdrList -> ADRLSIT to show
  621. lpszTitle = string to identify this dump
  622. Returns : none
  623. Comment :
  624. ***************************************************************************/
  625. void _DebugADRLIST(LPADRLIST lpAdrList, LPTSTR lpszTitle) {
  626. ULONG i;
  627. TCHAR szTitle[250];
  628. for (i = 0; i < lpAdrList->cEntries; i++) {
  629. wnsprintf(szTitle, ARRAYSIZE(szTitle), "%s : Entry %u", lpszTitle, i);
  630. _DebugProperties(lpAdrList->aEntries[i].rgPropVals,
  631. lpAdrList->aEntries[i].cValues, szTitle);
  632. }
  633. }
  634. /***************************************************************************
  635. Name : DebugObjectProps
  636. Purpose : Displays MAPI properties of an object
  637. Parameters: fMAPI = TRUE if this is a MAPI object, FALSE if WAB
  638. lpObject -> object to dump
  639. Label = string to identify this prop dump
  640. Returns : none
  641. Comment :
  642. ***************************************************************************/
  643. void _DebugObjectProps(BOOL fMAPI, LPMAPIPROP lpObject, LPTSTR Label) {
  644. DWORD cProps = 0;
  645. LPSPropValue lpProps = NULL;
  646. HRESULT hr = hrSuccess;
  647. SCODE sc = SUCCESS_SUCCESS;
  648. hr = lpObject->lpVtbl->GetProps(lpObject, NULL, 0, &cProps, &lpProps);
  649. switch (sc = GetScode(hr)) {
  650. case SUCCESS_SUCCESS:
  651. break;
  652. case MAPI_W_ERRORS_RETURNED:
  653. DebugTrace("GetProps -> Errors Returned\n");
  654. break;
  655. default:
  656. DebugTrace("GetProps -> Error 0x%x\n", sc);
  657. return;
  658. }
  659. _DebugProperties(lpProps, cProps, Label);
  660. FreeBufferAndNull(fMAPI, &lpProps);
  661. }
  662. /*
  663. * Destroys an SRowSet structure.
  664. */
  665. STDAPI_(void)
  666. MyFreeProws(BOOL fMAPI, LPSRowSet prows)
  667. {
  668. ULONG irow;
  669. if (!prows)
  670. return;
  671. for (irow = 0; irow < prows->cRows; ++irow)
  672. FreeBufferAndNull(fMAPI, &(prows->aRow[irow].lpProps));
  673. FreeBufferAndNull(fMAPI, &prows);
  674. }
  675. /***************************************************************************
  676. Name : DebugMapiTable
  677. Purpose : Displays structure of a MAPITABLE including properties
  678. Parameters: fMAPI = TRUE if this is a MAPI object, FALSE if WAB
  679. lpTable -> MAPITABLE to display
  680. Returns : none
  681. Comment : Don't sort the columns or rows here. This routine should
  682. not produce side effects in the table.
  683. ***************************************************************************/
  684. void _DebugMapiTable(BOOL fMAPI, LPMAPITABLE lpTable) {
  685. UCHAR szTemp[30]; // plenty for "ROW %u"
  686. ULONG ulCount;
  687. WORD wIndex;
  688. LPSRowSet lpsRow = NULL;
  689. ULONG ulCurrentRow = (ULONG)-1;
  690. ULONG ulNum, ulDen, lRowsSeeked;
  691. DebugTrace("=======================================\n");
  692. DebugTrace("+ Dump of MAPITABLE at 0x%x:\n", lpTable);
  693. DebugTrace("---------------------------------------\n");
  694. // How big is the table?
  695. lpTable->lpVtbl->GetRowCount(lpTable, 0, &ulCount);
  696. DebugTrace("Table contains %u rows\n", ulCount);
  697. // Save the current position in the table
  698. lpTable->lpVtbl->QueryPosition(lpTable, &ulCurrentRow, &ulNum, &ulDen);
  699. // Display the properties for each row in the table
  700. for (wIndex = 0; wIndex < ulCount; wIndex++) {
  701. // Get the next row
  702. lpTable->lpVtbl->QueryRows(lpTable, 1, 0, &lpsRow);
  703. if (lpsRow) {
  704. // Assert(lpsRow->cRows == 1); // should have exactly one row
  705. wnsprintf(szTemp, ARRAYSIZE(szTemp), "ROW %u", wIndex);
  706. _DebugProperties(lpsRow->aRow[0].lpProps,
  707. lpsRow->aRow[0].cValues, szTemp);
  708. MyFreeProws(fMAPI, lpsRow);
  709. }
  710. }
  711. // Restore the current position for the table
  712. if (ulCurrentRow != (ULONG)-1) {
  713. lpTable->lpVtbl->SeekRow(lpTable, BOOKMARK_BEGINNING, ulCurrentRow,
  714. &lRowsSeeked);
  715. }
  716. }
  717. /*
  718. * DebugTrace -- printf to the debugger console or debug output file
  719. * Takes printf style arguments.
  720. * Expects newline characters at the end of the string.
  721. */
  722. VOID FAR CDECL _DebugTrace(LPSTR lpszFmt, ...) {
  723. va_list marker;
  724. TCHAR String[1100];
  725. va_start(marker, lpszFmt);
  726. wvnsprintf(String, ARRAYSIZE(String), lpszFmt, marker);
  727. OutputDebugString(String);
  728. }
  729. int EXPORTDBG __cdecl DebugTraceFn(char *pszFormat, ...) {
  730. va_list marker;
  731. TCHAR String[1100];
  732. va_start(marker, pszFormat);
  733. wvnsprintf(String, ARRAYSIZE(String), pszFormat, marker);
  734. OutputDebugString(String);
  735. return(0);
  736. }
  737. /*
  738. * DebugAssert
  739. *
  740. * From MAPI 1.0 SDK sample code
  741. */
  742. int __cdecl DebugAssert(int fFatal, char *pszFile, int iLine,
  743. char *pszFormat, ...) {
  744. char sz[512];
  745. va_list vl;
  746. int id;
  747. StrCpyN(sz, "++++ WAB Debug Trap (", ARRAYSIZE(sz));
  748. OutputDebugString(sz);
  749. va_start(vl, pszFormat);
  750. wvnsprintf(sz, ARRAYSIZE(sz), pszFormat, vl);
  751. va_end(vl);
  752. wsprintf(sz + lstrlen(sz), "\n[File %s, Line %d]\n\n", pszFile, iLine);
  753. OutputDebugString(sz);
  754. // Hold down control key to prevent MessageBox
  755. if (GetAsyncKeyState(VK_CONTROL) >= 0) {
  756. id = MessageBox(NULL,
  757. sz,
  758. "Microsoft Windows Address Book Debug Trap",
  759. MB_ABORTRETRYIGNORE | MB_ICONHAND | MB_SYSTEMMODAL |
  760. (fFatal ? MB_DEFBUTTON1 : MB_DEFBUTTON3) );
  761. if (id == IDABORT)
  762. *((LPBYTE)NULL) = 0;
  763. else if (id == IDRETRY)
  764. DebugBreak();
  765. }
  766. return(0);
  767. }
  768. int EXPORTDBG __cdecl DebugTrapFn(int fFatal, char *pszFile, int iLine, char *pszFormat, ...) {
  769. char sz[512];
  770. va_list vl;
  771. int id;
  772. lstrcpy(sz, "++++ WAB Debug Trap (");
  773. OutputDebugString(sz);
  774. va_start(vl, pszFormat);
  775. wvsprintf(sz, pszFormat, vl);
  776. va_end(vl);
  777. wsprintf(sz + lstrlen(sz), "\n[File %s, Line %d]\n\n", pszFile, iLine);
  778. OutputDebugString(sz);
  779. // Hold down control key to prevent MessageBox
  780. if (GetAsyncKeyState(VK_CONTROL) >= 0) {
  781. id = MessageBox(NULL,
  782. sz,
  783. "Microsoft Windows Address Book Debug Trap",
  784. MB_ABORTRETRYIGNORE | MB_ICONHAND | MB_SYSTEMMODAL |
  785. (fFatal ? MB_DEFBUTTON1 : MB_DEFBUTTON3) );
  786. if (id == IDABORT)
  787. *((LPBYTE)NULL) = 0;
  788. else if (id == IDRETRY)
  789. DebugBreak();
  790. }
  791. return(0);
  792. }
  793. #endif