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.

10127 lines
297 KiB

  1. #include "wabtest.h"
  2. #include <assert.h>
  3. #include "resource.h"
  4. #include "..\luieng.dll\luieng.h"
  5. #include "wabtest.h"
  6. #define IDM_CREATEENTRIES 2000
  7. #define IDM_ENUMERATEALL 2001
  8. #define IDM_DELETEENTRIES 2002
  9. #define IDM_DELETEALL 2003
  10. #define IDM_DELETEUSERSONLY 2004
  11. #define IDM_CREATEONEOFF 2005
  12. #define IDM_RESOLVENAME 2006
  13. #define IDM_SETPROPS 2007
  14. #define IDM_QUERYINTERFACE 2008
  15. #define IDM_PREPARERECIPS 2009
  16. #define IDM_COPYENTRIES 2010
  17. #define IDM_RUNBVT 2011
  18. #define IDM_ALLOCATEBUFFER 2012
  19. #define IDM_ALLOCATEMORE 2013
  20. #define IDM_FREEBUFFER 2014
  21. #define IDM_IABOPENENTRY 2015
  22. #define IDM_ICCREATEENTRY 2016
  23. #define IDM_IMUSETGETPROPS 2017
  24. #define IDM_IMUSAVECHANGES 2018
  25. #define IDM_ICRESOLVENAMES 2019
  26. #define IDM_ICOPENENTRY 2020
  27. #define IDM_IABADDRESS 2021
  28. #define IDM_ADDMULTIPLE 2022
  29. #define IDM_IABRESOLVENAME 2023
  30. #define IDM_MULTITHREAD 2024
  31. #define IDM_IABNEWENTRYDET 2025
  32. #define IDM_DELWAB 2026
  33. #define IDM_PERFORMANCE 2027
  34. #define IDM_IDLSUITE 2028
  35. #define IDM_NAMEDPROPS 2029
  36. #define IDM_SETINIFILE 2501
  37. #define ID_MULTITHREADCOMPLETE 2502
  38. //
  39. // Globals
  40. //
  41. GUID WabTestGUID = { /* 683ce274-343a-11d0-9ff1-00a0c905424c */
  42. 0x683ce274,
  43. 0x343a,
  44. 0x11d0,
  45. {0x9f, 0xf1, 0x00, 0xa0, 0xc9, 0x05, 0x42, 0x4c}
  46. };
  47. static char szAppName[]= "WABTESTS";
  48. char szIniFile[BIG_BUF];
  49. CRITICAL_SECTION CriticalSection;
  50. ULONG glblCount = 0, glblTest = 39, glblDN = 0;
  51. #ifdef PAB
  52. LPMAPISESSION lpMAPISession; //Global handle to session
  53. #endif
  54. #ifdef WAB
  55. LPWABOBJECT lpWABObject; //Global handle to session
  56. LPADRBOOK glbllpAdrBook;
  57. #endif
  58. DWORD ThreadIdJunk;
  59. HWND glblhwnd;
  60. HINSTANCE hinstLib, glblhinst;
  61. HANDLE glblThreadManager;
  62. LUIINIT LUIInit;
  63. LUIMSGHANDLER LUIMsgHandler;
  64. LUIOUT LUIOut;
  65. BOOL bLUIInit, glblStop, Seeded;
  66. //***************************************************************
  67. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  68. LPSTR lpszCmdLine, int nCmdShow)
  69. {
  70. HWND hwnd;
  71. MSG msg;
  72. WNDCLASS wndclass;
  73. //
  74. // Init Global Variables Here
  75. //
  76. #ifdef PAB
  77. lpMAPISession = NULL;
  78. #endif
  79. glblThreadManager = NULL;
  80. bLUIInit = FALSE;
  81. glblStop = FALSE;
  82. Seeded = FALSE;
  83. if (!hPrevInstance)
  84. {
  85. wndclass.style = CS_HREDRAW|CS_VREDRAW;
  86. wndclass.lpfnWndProc = WndProc;
  87. wndclass.hInstance = hInstance;
  88. wndclass.cbClsExtra = 4;
  89. wndclass.cbWndExtra = 0;
  90. wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
  91. wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  92. wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
  93. wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  94. wndclass.lpszClassName = szAppName;
  95. RegisterClass(&wndclass);
  96. }
  97. hwnd = CreateWindow(szAppName,"WABTests", WS_OVERLAPPEDWINDOW,
  98. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,
  99. NULL, NULL, hInstance, NULL);
  100. hinstLib = LoadLibrary("luieng.dll");
  101. if (hinstLib) {
  102. LUIInit = (LUIINIT)GetProcAddress(hinstLib,"LUIInit");
  103. LUIMsgHandler=(LUIMSGHANDLER)GetProcAddress(hinstLib,"LUIMsgHandler");
  104. LUIOut = (LUIOUT)GetProcAddress(hinstLib,"LUIOut");
  105. lstrcpy(szIniFile,INIFILENAME);
  106. MenuStruct Tests[MAXMENU];
  107. MenuStruct Tools[MAXMENU];
  108. MenuStruct TestSettings[MAXMENU];
  109. memset((void *)Tests,0,sizeof(Tests));
  110. memset((void *)Tools,0,sizeof(Tests));
  111. memset((void *)TestSettings,0,sizeof(TestSettings));
  112. Tests[0].nType = LINE;
  113. Tests[1].nItemID = IDM_ALLOCATEBUFFER;
  114. Tests[1].nType = NORMAL;
  115. lstrcpy(Tests[1].lpszItemName,"&AllocateBuffer");
  116. Tests[2].nItemID = IDM_ALLOCATEMORE;
  117. Tests[2].nType = NORMAL;
  118. lstrcpy(Tests[2].lpszItemName,"&AllocateMore");
  119. Tests[3].nItemID = IDM_FREEBUFFER;
  120. Tests[3].nType = NORMAL;
  121. lstrcpy(Tests[3].lpszItemName,"&FreeBuffer");
  122. Tests[4].nItemID = IDM_IABOPENENTRY;
  123. Tests[4].nType = NORMAL;
  124. lstrcpy(Tests[4].lpszItemName,"IAB->OpenEntry");
  125. Tests[5].nItemID = IDM_IABADDRESS;
  126. Tests[5].nType = NORMAL;
  127. lstrcpy(Tests[5].lpszItemName,"IAB->Address");
  128. Tests[6].nItemID = IDM_IABRESOLVENAME;
  129. Tests[6].nType = NORMAL;
  130. lstrcpy(Tests[6].lpszItemName,"IAB->ResolveName");
  131. Tests[7].nItemID = IDM_IABNEWENTRYDET;
  132. Tests[7].nType = NORMAL;
  133. lstrcpy(Tests[7].lpszItemName,"IAB->NewEntry/Det");
  134. Tests[8].nItemID = IDM_ICCREATEENTRY;
  135. Tests[8].nType = NORMAL;
  136. lstrcpy(Tests[8].lpszItemName,"ICtr->CreateEntry");
  137. Tests[9].nItemID = IDM_ICRESOLVENAMES;
  138. Tests[9].nType = NORMAL;
  139. lstrcpy(Tests[9].lpszItemName,"ICtr->ResolveNames");
  140. Tests[10].nItemID = IDM_ICOPENENTRY;
  141. Tests[10].nType = NORMAL;
  142. lstrcpy(Tests[10].lpszItemName,"ICtr->OpenEntry");
  143. Tests[11].nItemID = IDM_IMUSETGETPROPS;
  144. Tests[11].nType = NORMAL;
  145. lstrcpy(Tests[11].lpszItemName,"IMU->Set/GetProps");
  146. Tests[12].nItemID = IDM_IMUSAVECHANGES;
  147. Tests[12].nType = NORMAL;
  148. lstrcpy(Tests[12].lpszItemName,"IMU->SaveChanges");
  149. Tests[13].nItemID = IDM_IDLSUITE;
  150. Tests[13].nType = NORMAL;
  151. lstrcpy(Tests[13].lpszItemName,"IDL Test Suite");
  152. Tests[14].nItemID = IDM_NAMEDPROPS;
  153. Tests[14].nType = NORMAL;
  154. lstrcpy(Tests[14].lpszItemName,"Named Props Suite");
  155. Tests[15].nType= ENDMENU;
  156. /* Tests[15].nType = LINE;
  157. Tests[16].nItemID = IDM_ADDMULTIPLE;
  158. Tests[16].nType = NORMAL;
  159. lstrcpy(Tests[16].lpszItemName,"AddMultipleEntries");
  160. Tests[17].nItemID = IDM_DELWAB;
  161. Tests[17].nType = NORMAL;
  162. lstrcpy(Tests[17].lpszItemName,"DeleteWABFile");
  163. Tests[18].nItemID = IDM_PERFORMANCE;
  164. Tests[18].nType = NORMAL;
  165. lstrcpy(Tests[18].lpszItemName,"Performance Suite");
  166. Tests[19].nItemID = IDM_MULTITHREAD;
  167. Tests[19].nType = NORMAL;
  168. lstrcpy(Tests[19].lpszItemName,"MultiThreadStress");
  169. Tests[6].nItemID = IDM_CREATEENTRIES;
  170. Tests[6].nType = NORMAL;
  171. lstrcpy(Tests[6].lpszItemName,"&CreateEntries");
  172. Tests[7].nItemID = IDM_ENUMERATEALL;
  173. Tests[7].nType = NORMAL;
  174. lstrcpy(Tests[7].lpszItemName,"&EnumerateAll");
  175. Tests[8].nItemID = IDM_DELETEENTRIES;
  176. Tests[8].nType = NORMAL;
  177. lstrcpy(Tests[8].lpszItemName,"&DeleteEntries");
  178. Tests[9].nItemID = IDM_DELETEALL;
  179. Tests[9].nType = NORMAL;
  180. lstrcpy(Tests[9].lpszItemName,"Delete&All");
  181. */
  182. TestSettings[0].nItemID = IDM_SETINIFILE;
  183. TestSettings[0].nType = NORMAL;
  184. lstrcpy(TestSettings[0].lpszItemName,"&INI File");
  185. TestSettings[1].nType = ENDMENU;
  186. Tools[0].nItemID = IDM_ADDMULTIPLE;
  187. Tools[0].nType = NORMAL;
  188. lstrcpy(Tools[0].lpszItemName,"AddMultipleEntries");
  189. Tools[1].nItemID = IDM_DELWAB;
  190. Tools[1].nType = NORMAL;
  191. lstrcpy(Tools[1].lpszItemName,"DeleteWABFile");
  192. Tools[2].nItemID = IDM_PERFORMANCE;
  193. Tools[2].nType = NORMAL;
  194. lstrcpy(Tools[2].lpszItemName,"Performance Suite");
  195. Tools[4].nType= ENDMENU;
  196. Tools[3].nItemID = IDM_MULTITHREAD;
  197. Tools[3].nType = NORMAL;
  198. lstrcpy(Tools[3].lpszItemName,"MultiThreadStress");
  199. bLUIInit = LUIInit(hwnd,Tests,Tools,/*TestSettings,*/FALSE);
  200. glblhwnd=hwnd;
  201. glblhinst=hInstance;
  202. ShowWindow(hwnd, nCmdShow);
  203. UpdateWindow(hwnd);
  204. while(GetMessage(&msg,NULL,0,0))
  205. {
  206. TranslateMessage(&msg);
  207. DispatchMessage(&msg);
  208. }
  209. FreeLibrary(hinstLib);
  210. }
  211. else MessageBox(NULL,"LoadLibrary Failed: Cannot find testcntl.dll","PabTest Error",MB_OK);
  212. return msg.wParam;
  213. }
  214. //***************************************************************
  215. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
  216. {
  217. static int i;
  218. DWORD retval;
  219. if (bLUIInit)
  220. LUIMsgHandler(message,wParam,lParam);
  221. switch(message)
  222. {
  223. case WM_CREATE:
  224. {
  225. i=0;
  226. return 0;
  227. }
  228. case WM_SIZE:
  229. {
  230. return 0;
  231. }
  232. case WM_COMMAND:
  233. {
  234. switch(LOWORD(wParam))
  235. {
  236. case IDM_STOP :
  237. glblStop = TRUE;
  238. break;
  239. case IDM_ALLOCATEBUFFER:
  240. if (PABAllocateBuffer()) {
  241. LUIOut(L1," ");
  242. LUIOut(LPASS,"AllocateBuffer: %d",i);
  243. }
  244. else {
  245. LUIOut(L1," ");
  246. LUIOut(LFAIL,"AllocateBuffer: %d",i);
  247. }
  248. i++;
  249. return 0;
  250. case IDM_ALLOCATEMORE:
  251. if (PABAllocateMore()) {
  252. LUIOut(L1," ");
  253. LUIOut(LPASS,"AllocateMore: %d",i);
  254. }
  255. else {
  256. LUIOut(L1," ");
  257. LUIOut(LFAIL,"AllocateMore: %d",i);
  258. }
  259. i++;
  260. return 0;
  261. case IDM_FREEBUFFER :
  262. if (PABFreeBuffer()) {
  263. LUIOut(L1," ");
  264. LUIOut(LPASS,"FreeBuffer: %d",i);
  265. }
  266. else {
  267. LUIOut(L1," ");
  268. LUIOut(LFAIL,"FreeBuffer: %d",i);
  269. }
  270. i++;
  271. return 0;
  272. case IDM_IABOPENENTRY :
  273. if (PAB_IABOpenEntry()) {
  274. LUIOut(L1," ");
  275. LUIOut(LPASS,"IAddrBook->OpenEntry: %d",i);
  276. }
  277. else {
  278. LUIOut(L1," ");
  279. LUIOut(LFAIL,"IAddrBook->OpenEntry: %d",i);
  280. }
  281. i++;
  282. return 0;
  283. case IDM_ICCREATEENTRY :
  284. if (PAB_IABContainerCreateEntry()) {
  285. LUIOut(L1," ");
  286. LUIOut(LPASS,"IABContainer->CreateEntry: %d",i);
  287. }
  288. else {
  289. LUIOut(L1," ");
  290. LUIOut(LFAIL,"IABContainer->CreateEntry: %d",i);
  291. }
  292. i++;
  293. return 0;
  294. case IDM_IMUSETGETPROPS :
  295. if (PAB_IMailUserSetGetProps()) {
  296. LUIOut(L1," ");
  297. LUIOut(LPASS,"IMailUser->Set/GetProps: %d",i);
  298. }
  299. else {
  300. LUIOut(L1," ");
  301. LUIOut(LFAIL,"IMailUser->Set/GetProps: %d",i);
  302. }
  303. i++;
  304. return 0;
  305. case IDM_IMUSAVECHANGES :
  306. if (PAB_IMailUserSaveChanges()) {
  307. LUIOut(L1," ");
  308. LUIOut(LPASS,"IMailUser->SaveChanges: %d",i);
  309. }
  310. else {
  311. LUIOut(L1," ");
  312. LUIOut(LFAIL,"IMailUser->SaveChanges: %d",i);
  313. }
  314. i++;
  315. return 0;
  316. case IDM_ICRESOLVENAMES :
  317. if (PAB_IABContainerResolveNames()) {
  318. LUIOut(L1," ");
  319. LUIOut(LPASS,"IABContainer->ResolveNames: %d",i);
  320. }
  321. else {
  322. LUIOut(L1," ");
  323. LUIOut(LFAIL,"IABContainer->ResolveNames: %d",i);
  324. }
  325. i++;
  326. return 0;
  327. case IDM_ICOPENENTRY :
  328. if (PAB_IABContainerOpenEntry()) {
  329. LUIOut(L1," ");
  330. LUIOut(LPASS,"IABContainer->OpenEntry: %d",i);
  331. }
  332. else {
  333. LUIOut(L1," ");
  334. LUIOut(LFAIL,"IABContainer->OpenEntry: %d",i);
  335. }
  336. i++;
  337. return 0;
  338. case IDM_IABADDRESS :
  339. if (PAB_IABAddress()) {
  340. LUIOut(L1," ");
  341. LUIOut(LPASS,"IAdrBook->Address: %d",i);
  342. }
  343. else {
  344. LUIOut(L1," ");
  345. LUIOut(LFAIL,"IAdrBook->Address: %d",i);
  346. }
  347. i++;
  348. return 0;
  349. case IDM_ADDMULTIPLE :
  350. if (PAB_AddMultipleEntries()) {
  351. LUIOut(L1," ");
  352. LUIOut(LPASS,"AddMultipleEntries: %d",i);
  353. }
  354. else {
  355. LUIOut(L1," ");
  356. LUIOut(LFAIL,"AddMultipleEntries: %d",i);
  357. }
  358. i++;
  359. return 0;
  360. case IDM_IABRESOLVENAME :
  361. if (PAB_IABResolveName()) {
  362. LUIOut(L1," ");
  363. LUIOut(LPASS,"IAdrBook->ResolveName: %d",i);
  364. }
  365. else {
  366. LUIOut(L1," ");
  367. LUIOut(LFAIL,"IAdrBook->ResolveName: %d",i);
  368. }
  369. i++;
  370. return 0;
  371. case IDM_IABNEWENTRYDET :
  372. if (PAB_IABNewEntry_Details()) {
  373. LUIOut(L1," ");
  374. LUIOut(LPASS,"IAdrBook->NewEntry/Details: %d",i);
  375. }
  376. else {
  377. LUIOut(L1," ");
  378. LUIOut(LFAIL,"IAdrBook->NewEntry/Details: %d",i);
  379. }
  380. i++;
  381. return 0;
  382. case IDM_CREATEENTRIES :
  383. if (PabCreateEntry()) {
  384. LUIOut(L1," ");
  385. LUIOut(LPASS,"Create Entries: %d",i);
  386. }
  387. else {
  388. LUIOut(L1," ");
  389. LUIOut(LFAIL,"Create Entries: %d",i);
  390. }
  391. i++;
  392. return 0;
  393. case IDM_MULTITHREAD :
  394. if (glblThreadManager) {
  395. LUIOut(L1, "In cleanup routine");
  396. TerminateThread(glblThreadManager, (DWORD)0);
  397. CloseHandle(glblThreadManager);
  398. }
  399. glblThreadManager =(HANDLE)CreateThread(
  400. (LPSECURITY_ATTRIBUTES) NULL, // pointer to thread security attributes
  401. (DWORD) 0, // initial thread stack size, in bytes
  402. (LPTHREAD_START_ROUTINE) ThreadManager, // pointer to thread function
  403. (LPVOID) NULL, // argument for new thread
  404. (DWORD) 0, // creation flags
  405. &ThreadIdJunk // pointer to returned thread identifier
  406. );
  407. if (!glblThreadManager) LUIOut(L1, "<ERROR> WndProc: CreateThread returned 0x%X", GetLastError());
  408. return 0;
  409. case ID_MULTITHREADCOMPLETE :
  410. if (glblThreadManager) {
  411. //GetExitCodeThread(glblThreadManager, &retval);
  412. retval = HIWORD(wParam);
  413. if (retval) {
  414. LUIOut(L1," ");
  415. LUIOut(LPASS,"MultiThreadStress: %d",i);
  416. }
  417. else {
  418. LUIOut(L1," ");
  419. LUIOut(LFAIL,"MultiThreadStress: %d",i);
  420. }
  421. CloseHandle(glblThreadManager);
  422. }
  423. glblStop = FALSE; //reset stop flag
  424. i++;
  425. return 0;
  426. case IDM_DELWAB :
  427. if (DeleteWABFile()) {
  428. LUIOut(L1," ");
  429. LUIOut(LPASS,"Delete WAB File: %d",i);
  430. }
  431. else {
  432. LUIOut(L1," ");
  433. LUIOut(LFAIL,"Delete WAB File: %d",i);
  434. }
  435. i++;
  436. return 0;
  437. case IDM_IDLSUITE :
  438. if (PAB_IDLSuite()) {
  439. LUIOut(L1," ");
  440. LUIOut(LPASS,"Distribution List Test Suite: %d",i);
  441. }
  442. else {
  443. LUIOut(L1," ");
  444. LUIOut(LFAIL,"Distribution List Test Suite: %d",i);
  445. }
  446. i++;
  447. return 0;
  448. case IDM_PERFORMANCE :
  449. if (Performance()) {
  450. LUIOut(L1," ");
  451. LUIOut(LPASS,"WAB Performance Suite: %d",i);
  452. }
  453. else {
  454. LUIOut(L1," ");
  455. LUIOut(LFAIL,"WAB Performance Suite: %d",i);
  456. }
  457. i++;
  458. return 0;
  459. case IDM_NAMEDPROPS :
  460. if (NamedPropsSuite()) {
  461. LUIOut(L1," ");
  462. LUIOut(LPASS,"Named Properties Test Suite: %d",i);
  463. }
  464. else {
  465. LUIOut(L1," ");
  466. LUIOut(LFAIL,"Named Properties Test Suite: %d",i);
  467. }
  468. i++;
  469. return 0;
  470. case IDM_ENUMERATEALL :
  471. if (PabEnumerateAll()) {
  472. LUIOut(L1," ");
  473. LUIOut(LPASS,"Enumerate All: %d",i);
  474. }
  475. else {
  476. LUIOut(L1," ");
  477. LUIOut(LFAIL,"Enumerate All: %d",i);
  478. }
  479. i++;
  480. return 0;
  481. case IDM_DELETEENTRIES :
  482. if (PabDeleteEntry()) {
  483. LUIOut(L1," ");
  484. LUIOut(LPASS,"Delete specified Entries: %d",i);
  485. }
  486. else {
  487. LUIOut(L1," ");
  488. LUIOut(LFAIL,"Delete specified Entries: %d",i);
  489. }
  490. i++;
  491. return 0;
  492. case IDM_DELETEALL:
  493. if (ClearPab(0)) {
  494. LUIOut(L1," ");
  495. LUIOut(LPASS,"Delete All Entries: %d",i);
  496. }
  497. else {
  498. LUIOut(L1," ");
  499. LUIOut(LFAIL,"Delete All Entries: %d",i);
  500. }
  501. i++;
  502. return 0;
  503. case IDM_DELETEUSERSONLY:
  504. if (ClearPab(1)) {
  505. LUIOut(L1," ");
  506. LUIOut(LPASS,"Delete Mail Users Only: %d",i);
  507. }
  508. else {
  509. LUIOut(L1," ");
  510. LUIOut(LFAIL,"Delete Mail Users Only: %d",i);
  511. }
  512. i++;
  513. return 0;
  514. case IDM_CREATEONEOFF :
  515. if (CreateOneOff()) {
  516. LUIOut(L1," ");
  517. LUIOut(LPASS,"CreateOneOff: %d",i);
  518. }
  519. else {
  520. LUIOut(L1," ");
  521. LUIOut(LFAIL,"CreateOneOff: %d",i);
  522. }
  523. i++;
  524. return 0;
  525. case IDM_RESOLVENAME :
  526. if (PABResolveName()) {
  527. LUIOut(L1," ");
  528. LUIOut(LPASS,"ResolveName: %d",i);
  529. }
  530. else {
  531. LUIOut(L1," ");
  532. LUIOut(LFAIL,"ResolveName: %d",i);
  533. }
  534. i++;
  535. return 0;
  536. case IDM_SETPROPS :
  537. if (PABSetProps()) {
  538. LUIOut(L1," ");
  539. LUIOut(LPASS,"SetProps: %d",i);
  540. }
  541. else {
  542. LUIOut(L1," ");
  543. LUIOut(LFAIL,"SetProps: %d",i);
  544. }
  545. i++;
  546. return 0;
  547. case IDM_QUERYINTERFACE :
  548. if (PABQueryInterface()) {
  549. LUIOut(L1," ");
  550. LUIOut(LPASS,"QueryInterface: %d",i);
  551. }
  552. else {
  553. LUIOut(L1," ");
  554. LUIOut(LFAIL,"QueryInterface: %d",i);
  555. }
  556. i++;
  557. return 0;
  558. case IDM_PREPARERECIPS :
  559. if (PABPrepareRecips()) {
  560. LUIOut(L1," ");
  561. LUIOut(LPASS,"PrepareRecips: %d",i);
  562. }
  563. else {
  564. LUIOut(L1," ");
  565. LUIOut(LFAIL,"PrepareRecips: %d",i);
  566. }
  567. i++;
  568. return 0;
  569. case IDM_COPYENTRIES :
  570. if (PABCopyEntries()) {
  571. LUIOut(L1," ");
  572. LUIOut(LPASS,"CopyEntries: %d",i);
  573. }
  574. else {
  575. LUIOut(L1," ");
  576. LUIOut(LFAIL,"CopyEntries: %d",i);
  577. }
  578. i++;
  579. return 0;
  580. case IDM_RUNBVT :
  581. if (PABRunBVT()) {
  582. LUIOut(L1," ");
  583. LUIOut(LPASS,"RunBVT: %d",i);
  584. }
  585. else {
  586. LUIOut(L1," ");
  587. LUIOut(LFAIL,"RunBVT: %d",i);
  588. }
  589. i++;
  590. return 0;
  591. case IDM_SETINIFILE :
  592. DialogBox(glblhinst, MAKEINTRESOURCE(IDD_INIFILE), glblhwnd, SetIniFile);
  593. return 0;
  594. }
  595. return 0;
  596. }
  597. case WM_DESTROY:
  598. {
  599. PostQuitMessage(0);
  600. return 0;
  601. }
  602. }
  603. return DefWindowProc(hwnd,message,wParam,lParam);
  604. }
  605. BOOL PABAllocateBuffer()
  606. {
  607. DWORD ** lppBuffer;
  608. //DWORD nCells, counter;
  609. ULONG ulFlags = 0;
  610. HRESULT hr = hrSuccess;
  611. SCODE sc = SUCCESS_SUCCESS;
  612. int retval=TRUE;
  613. LPADRBOOK lpAdrBook = NULL;
  614. LPABCONT lpPABCont= NULL;
  615. LPABCONT lpDLCont= NULL;
  616. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  617. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  618. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  619. ULONG cbEid=0; // entry id of the entry being added
  620. LPENTRYID lpEid=NULL;
  621. ULONG cValues = 0, ulObjType=NULL;
  622. ULONG cRows = 0;
  623. ULONG iEntry = 0;
  624. int i=0,k=0;
  625. LPMAPITABLE lpContentsTable = NULL;
  626. LPSRowSet lpRowSet = NULL;
  627. LPMAILUSER lpAddress = NULL;
  628. SPropValue PropValue[3] = {0}; // This value is 3 because we
  629. // will be setting 3 properties:
  630. // EmailAddress, DisplayName and
  631. // AddressType.
  632. LUIOut(L1," ");
  633. LUIOut(L1,"Running AllocateBuffer");
  634. LUIOut(L2,"-> Allocates and confirms memory using the Allocate Buffer");
  635. LUIOut(L2, " routine. confirms by writing a bit pattern and verifying.");
  636. LUIOut(L1," ");
  637. if (!GetAB(OUT &lpAdrBook)) {
  638. retval = FALSE;
  639. goto out;
  640. }
  641. // Allocate a buffer and check for success
  642. lppBuffer = new (DWORD*);
  643. #ifdef PAB
  644. if ((MAPIAllocateBuffer(BUFFERSIZE, (LPVOID FAR *)lppBuffer) == S_OK) && *lppBuffer)
  645. LUIOut(L2,"MAPIAllocateBuffer PASSED");
  646. else {
  647. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  648. retval = FALSE;
  649. goto out;
  650. }
  651. #endif
  652. #ifdef WAB
  653. if ((lpWABObject->AllocateBuffer(BUFFERSIZE, (LPVOID FAR *)lppBuffer) == S_OK) && *lppBuffer)
  654. LUIOut(L2,"lpWABObject->AllocateBuffer PASSED");
  655. else {
  656. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  657. retval = FALSE;
  658. goto out;
  659. }
  660. #endif
  661. if ( !VerifyBuffer(lppBuffer,BUFFERSIZE) )
  662. retval = FALSE;
  663. out:
  664. #ifdef PAB
  665. if (*lppBuffer) {
  666. if (MAPIFreeBuffer(*lppBuffer) == S_OK)
  667. LUIOut(L2,"MAPIFreeBuffer Succeded");
  668. else LUIOut(L2,"MAPIFreeBuffer Failed");
  669. }
  670. if (lpEid)
  671. MAPIFreeBuffer(lpEid);
  672. if (lpEidPAB)
  673. MAPIFreeBuffer(lpEidPAB);
  674. #endif
  675. #ifdef WAB
  676. if (*lppBuffer) {
  677. if (lpWABObject->FreeBuffer(*lppBuffer) == S_OK)
  678. LUIOut(L2,"lpWABObject->FreeBuffer Succeded");
  679. else LUIOut(L2,"lpWABObject->FreeBuffer Failed");
  680. }
  681. if (lpEid)
  682. lpWABObject->FreeBuffer(lpEid);
  683. if (lpEidPAB)
  684. lpWABObject->FreeBuffer(lpEidPAB);
  685. #endif
  686. if (lpContentsTable)
  687. lpContentsTable->Release();
  688. if (lpPABCont)
  689. lpPABCont->Release();
  690. if (lpDLCont)
  691. lpDLCont->Release();
  692. if (lpAdrBook)
  693. lpAdrBook->Release();
  694. #ifdef PAB
  695. if (lpMAPISession)
  696. lpMAPISession->Release();
  697. MAPIUninitialize();
  698. #endif
  699. #ifdef WAB
  700. if (lpWABObject)
  701. lpWABObject->Release();
  702. #endif
  703. return retval;
  704. }
  705. BOOL PABAllocateMore()
  706. {
  707. DWORD ** lppBuffer, ** lppBuffer2, ** lppBuffer3;
  708. //DWORD nCells, counter;
  709. ULONG ulFlags = 0;
  710. HRESULT hr = hrSuccess;
  711. SCODE sc = SUCCESS_SUCCESS;
  712. int retval=TRUE;
  713. LPADRBOOK lpAdrBook = NULL;
  714. LPABCONT lpPABCont= NULL;
  715. LPABCONT lpDLCont= NULL;
  716. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  717. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  718. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  719. ULONG cbEid=0; // entry id of the entry being added
  720. LPENTRYID lpEid=NULL;
  721. ULONG cValues = 0, ulObjType=NULL;
  722. ULONG cRows = 0;
  723. ULONG iEntry = 0;
  724. int i=0,k=0;
  725. LPMAPITABLE lpContentsTable = NULL;
  726. LPSRowSet lpRowSet = NULL;
  727. LPMAILUSER lpAddress = NULL;
  728. LUIOut(L1," ");
  729. LUIOut(L1,"Running AllocateMore");
  730. LUIOut(L2,"-> Allocates memory using the AllocateBuffer routine");
  731. LUIOut(L2, " followed by two calls to AllocateMore using different");
  732. LUIOut(L2, " buffer sizes. It then confirms the buffer by writing");
  733. LUIOut(L2, " a bit pattern and verifying.");
  734. LUIOut(L1," ");
  735. if (!GetAB(OUT &lpAdrBook)) {
  736. retval = FALSE;
  737. goto out;
  738. }
  739. // Allocate a buffer and check for success
  740. lppBuffer = new (DWORD*);
  741. #ifdef PAB
  742. if ((MAPIAllocateBuffer(BUFFERSIZE, (LPVOID FAR *)lppBuffer) == S_OK) && *lppBuffer)
  743. LUIOut(L2,"MAPIAllocateBuffer PASSED");
  744. else {
  745. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  746. retval = FALSE;
  747. goto out;
  748. }
  749. #endif
  750. #ifdef WAB
  751. if ((lpWABObject->AllocateBuffer(BUFFERSIZE, (LPVOID FAR *)lppBuffer) == S_OK) && *lppBuffer)
  752. LUIOut(L2,"lpWABObject->AllocateBuffer PASSED");
  753. else {
  754. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  755. retval = FALSE;
  756. goto out;
  757. }
  758. #endif
  759. lppBuffer2 = new (DWORD*);
  760. #ifdef PAB
  761. if ((MAPIAllocateMore(BUFFERSIZE2, *lppBuffer, (LPVOID FAR *)lppBuffer2) == S_OK)
  762. && *lppBuffer)
  763. LUIOut(L2,"MAPIAllocateMore PASSED, %u bytes allocated", BUFFERSIZE2);
  764. else {
  765. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  766. retval = FALSE;
  767. goto out;
  768. }
  769. #endif
  770. #ifdef WAB
  771. if ((lpWABObject->AllocateMore(BUFFERSIZE2, *lppBuffer, (LPVOID FAR *)lppBuffer2) == S_OK)
  772. && *lppBuffer)
  773. LUIOut(L2,"lpWABObject->AllocateMore PASSED, %u bytes allocated", BUFFERSIZE2);
  774. else {
  775. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  776. retval = FALSE;
  777. goto out;
  778. }
  779. #endif
  780. lppBuffer3 = new (DWORD*);
  781. #ifdef PAB
  782. if ((MAPIAllocateMore(BUFFERSIZE3, *lppBuffer, (LPVOID FAR *)lppBuffer3) == S_OK)
  783. && *lppBuffer)
  784. LUIOut(L2,"MAPIAllocateMore PASSED, %u bytes allocated", BUFFERSIZE3);
  785. else {
  786. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  787. retval = FALSE;
  788. goto out;
  789. }
  790. #endif
  791. #ifdef WAB
  792. if ((lpWABObject->AllocateMore(BUFFERSIZE3, *lppBuffer, (LPVOID FAR *)lppBuffer3) == S_OK)
  793. && *lppBuffer)
  794. LUIOut(L2,"lpWABObject->AllocateMore PASSED, %u bytes allocated", BUFFERSIZE3);
  795. else {
  796. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  797. retval = FALSE;
  798. goto out;
  799. }
  800. #endif
  801. if ( !VerifyBuffer(lppBuffer,BUFFERSIZE) )
  802. retval = FALSE;
  803. if ( !VerifyBuffer(lppBuffer2,BUFFERSIZE2) )
  804. retval = FALSE;
  805. if ( !VerifyBuffer(lppBuffer3,BUFFERSIZE3) )
  806. retval = FALSE;
  807. out:
  808. #ifdef PAB
  809. if (*lppBuffer) {
  810. if (MAPIFreeBuffer(*lppBuffer) == S_OK)
  811. LUIOut(L2,"MAPIFreeBuffer Succeded");
  812. else LUIOut(L2,"MAPIFreeBuffer Failed");
  813. }
  814. if (lpEid)
  815. MAPIFreeBuffer(lpEid);
  816. if (lpEidPAB)
  817. MAPIFreeBuffer(lpEidPAB);
  818. #endif
  819. #ifdef WAB
  820. if (*lppBuffer) {
  821. if (lpWABObject->FreeBuffer(*lppBuffer) == S_OK)
  822. LUIOut(L2,"lpWABObject->FreeBuffer Succeded");
  823. else LUIOut(L2,"lpWABObject->FreeBuffer Failed");
  824. }
  825. if (lpEid)
  826. lpWABObject->FreeBuffer(lpEid);
  827. if (lpEidPAB)
  828. lpWABObject->FreeBuffer(lpEidPAB);
  829. #endif
  830. if (lpAddress)
  831. lpAddress->Release();
  832. if (lpContentsTable)
  833. lpContentsTable->Release();
  834. if (lpPABCont)
  835. lpPABCont->Release();
  836. if (lpDLCont)
  837. lpDLCont->Release();
  838. if (lpAdrBook)
  839. lpAdrBook->Release();
  840. #ifdef PAB
  841. if (lpMAPISession)
  842. lpMAPISession->Release();
  843. MAPIUninitialize();
  844. #endif
  845. #ifdef WAB
  846. if (lpWABObject)
  847. lpWABObject->Release();
  848. #endif
  849. return retval;
  850. }
  851. BOOL PABFreeBuffer()
  852. {
  853. DWORD ** lppBuffer, ** lppBuffer2, ** lppBuffer3;
  854. //DWORD nCells, counter;
  855. ULONG ulFlags = 0;
  856. HRESULT hr = hrSuccess;
  857. SCODE sc = SUCCESS_SUCCESS;
  858. int retval=TRUE;
  859. LPADRBOOK lpAdrBook = NULL;
  860. LPABCONT lpPABCont= NULL;
  861. LPABCONT lpDLCont= NULL;
  862. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  863. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  864. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  865. ULONG cbEid=0; // entry id of the entry being added
  866. LPENTRYID lpEid=NULL;
  867. ULONG cValues = 0, ulObjType=NULL;
  868. ULONG cRows = 0;
  869. ULONG iEntry = 0;
  870. int i=0,k=0;
  871. LPMAPITABLE lpContentsTable = NULL;
  872. LPSRowSet lpRowSet = NULL;
  873. LPMAILUSER lpAddress = NULL;
  874. LUIOut(L1," ");
  875. LUIOut(L1,"Running FreeBuffer");
  876. LUIOut(L2,"-> Allocates memory using the AllocateBuffer routine");
  877. LUIOut(L2, " followed by two calls to AllocateMore using different");
  878. LUIOut(L2, " buffer sizes. It then frees the initial buffer and verifies");
  879. LUIOut(L2, " that all 3 pointers are nullified.");
  880. LUIOut(L1," ");
  881. if (!GetAB(OUT &lpAdrBook)) {
  882. retval = FALSE;
  883. goto out;
  884. }
  885. // Allocate a buffer and check for success
  886. lppBuffer = new (DWORD*);
  887. #ifdef PAB
  888. if ((MAPIAllocateBuffer(BUFFERSIZE, (LPVOID FAR *)lppBuffer) == S_OK) && *lppBuffer)
  889. LUIOut(L2,"MAPIAllocateBuffer PASSED");
  890. else {
  891. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  892. retval = FALSE;
  893. goto out;
  894. }
  895. #endif
  896. #ifdef WAB
  897. if ((lpWABObject->AllocateBuffer(BUFFERSIZE, (LPVOID FAR *)lppBuffer) == S_OK) && *lppBuffer)
  898. LUIOut(L2,"lpWABObject->AllocateBuffer PASSED");
  899. else {
  900. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  901. retval = FALSE;
  902. goto out;
  903. }
  904. #endif
  905. lppBuffer2 = new (DWORD*);
  906. #ifdef PAB
  907. if ((MAPIAllocateMore(BUFFERSIZE2, *lppBuffer, (LPVOID FAR *)lppBuffer2) == S_OK)
  908. && *lppBuffer)
  909. LUIOut(L2,"MAPIAllocateMore PASSED, %u bytes allocated", BUFFERSIZE2);
  910. else {
  911. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  912. retval = FALSE;
  913. goto out;
  914. }
  915. #endif
  916. #ifdef WAB
  917. if ((lpWABObject->AllocateMore(BUFFERSIZE2, *lppBuffer, (LPVOID FAR *)lppBuffer2) == S_OK)
  918. && *lppBuffer)
  919. LUIOut(L2,"lpWABObject->AllocateMore PASSED, %u bytes allocated", BUFFERSIZE2);
  920. else {
  921. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  922. retval = FALSE;
  923. goto out;
  924. }
  925. #endif
  926. lppBuffer3 = new (DWORD*);
  927. #ifdef PAB
  928. if ((MAPIAllocateMore(BUFFERSIZE3, *lppBuffer, (LPVOID FAR *)lppBuffer3) == S_OK)
  929. && *lppBuffer)
  930. LUIOut(L2,"MAPIAllocateMore PASSED, %u bytes allocated", BUFFERSIZE3);
  931. else {
  932. LUIOut(L2,"MAPIAllocateBuffer FAILED");
  933. retval = FALSE;
  934. goto out;
  935. }
  936. #endif
  937. #ifdef WAB
  938. if ((lpWABObject->AllocateMore(BUFFERSIZE3, *lppBuffer, (LPVOID FAR *)lppBuffer3) == S_OK)
  939. && *lppBuffer)
  940. LUIOut(L2,"lpWABObject->AllocateMore PASSED, %u bytes allocated", BUFFERSIZE3);
  941. else {
  942. LUIOut(L2,"lpWABObject->AllocateBuffer FAILED");
  943. retval = FALSE;
  944. goto out;
  945. }
  946. #endif
  947. // Now free the original buffer
  948. #ifdef PAB
  949. if (*lppBuffer) {
  950. if (MAPIFreeBuffer(*lppBuffer) == S_OK)
  951. LUIOut(L2,"Call to MAPIFreeBuffer Succeded");
  952. else {
  953. LUIOut(L2,"Call to MAPIFreeBuffer Failed");
  954. }
  955. }
  956. #endif
  957. #ifdef WAB
  958. if (*lppBuffer) {
  959. if (lpWABObject->FreeBuffer(*lppBuffer) == S_OK)
  960. LUIOut(L2,"Call to lpWABObject->FreeBuffer Succeded");
  961. else {
  962. LUIOut(L2,"Call to lpWABObject->FreeBuffer Failed");
  963. }
  964. }
  965. #endif
  966. /*
  967. dwTest = INVALIDPTR;
  968. //Verify all 3 pointers are now null
  969. if (IsBadReadPtr(*lppBuffer,BUFFERSIZE)&&IsBadReadPtr(*lppBuffer2, BUFFERSIZE2)
  970. &&IsBadReadPtr(*lppBuffer3, BUFFERSIZE3)){
  971. LUIOut(L2,"MAPIFreeBuffer Succeded, all pointers are invalidated");
  972. }
  973. else {
  974. LUIOut(L2,"MAPIFreeBuffer Failed to invalidate all pointers");
  975. retval = FALSE;
  976. }
  977. */
  978. out:
  979. #ifdef PAB
  980. if (lpEid)
  981. MAPIFreeBuffer(lpEid);
  982. if (lpEidPAB)
  983. MAPIFreeBuffer(lpEidPAB);
  984. #endif
  985. #ifdef WAB
  986. if (lpEid)
  987. lpWABObject->FreeBuffer(lpEid);
  988. if (lpEidPAB)
  989. lpWABObject->FreeBuffer(lpEidPAB);
  990. #endif
  991. if (lpAddress)
  992. lpAddress->Release();
  993. if (lpContentsTable)
  994. lpContentsTable->Release();
  995. if (lpPABCont)
  996. lpPABCont->Release();
  997. if (lpDLCont)
  998. lpDLCont->Release();
  999. if (lpAdrBook)
  1000. lpAdrBook->Release();
  1001. #ifdef PAB
  1002. if (lpMAPISession)
  1003. lpMAPISession->Release();
  1004. MAPIUninitialize();
  1005. #endif
  1006. #ifdef WAB
  1007. if (lpWABObject)
  1008. lpWABObject->Release();
  1009. #endif
  1010. return retval;
  1011. }
  1012. BOOL PAB_IABOpenEntry()
  1013. {
  1014. //DWORD nCells, counter;
  1015. ULONG ulFlags = 0;
  1016. HRESULT hr = hrSuccess;
  1017. SCODE sc = SUCCESS_SUCCESS;
  1018. int retval=TRUE;
  1019. LPADRBOOK lpAdrBook = NULL;
  1020. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  1021. LPABCONT lpDLCont= NULL;
  1022. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  1023. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  1024. ULONG cbEid=0; // entry id of the entry being added
  1025. ULONG cbEidPAB = 0;
  1026. LPENTRYID lpEid=NULL;
  1027. ULONG cValues = 0, ulObjType=NULL;
  1028. ULONG cRows = 0;
  1029. ULONG iEntry = 0;
  1030. int i=0,k=0;
  1031. LPMAPITABLE lpContentsTable = NULL;
  1032. LPSRowSet lpRowSet = NULL;
  1033. LPMAILUSER lpAddress = NULL;
  1034. SPropValue PropValue[3] = {0}; // This value is 3 because we
  1035. // will be setting 3 properties:
  1036. // EmailAddress, DisplayName and
  1037. // AddressType.
  1038. SizedSPropTagArray(2, Cols) = { 2, {PR_OBJECT_TYPE, PR_ENTRYID } };
  1039. LPSPropValue lpSPropValueAddress = NULL;
  1040. LPSPropValue lpSPropValueEntryID = NULL;
  1041. LPSPropValue lpSPropValueDL = NULL;
  1042. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  1043. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  1044. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  1045. LUIOut(L1," ");
  1046. LUIOut(L1,"Running PAB_IABOpenEntry");
  1047. LUIOut(L2,"-> Verifies IAddrBook->OpenEntry is functional by checking the following:");
  1048. LUIOut(L2, " # The return code from OpenEntry");
  1049. LUIOut(L2, " # The object type returned is compared to MAPI_ABCONT");
  1050. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1051. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1052. LUIOut(L2, " count is tested for <= 0 (pass)");
  1053. LUIOut(L1," ");
  1054. if (!GetAB(OUT &lpAdrBook)) {
  1055. retval = FALSE;
  1056. goto out;
  1057. }
  1058. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  1059. assert(lpAdrBook != NULL);
  1060. LUIOut(L2, "Calling IABOpenEntry");
  1061. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  1062. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  1063. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  1064. if (HR_FAILED(hr) || (!lpABCont)) {
  1065. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  1066. retval=FALSE;
  1067. goto out;
  1068. }
  1069. LUIOut(L3, "The call to IABOpenEntry PASSED");
  1070. // Check to make sure the object type is what we expect
  1071. LUIOut(L3, "Checking to make sure the returned object type is correct");
  1072. if (ulObjType != MAPI_ABCONT) {
  1073. LUIOut(L2, "Object type is not MAPI_ABCONT");
  1074. retval = FALSE;
  1075. goto out;
  1076. }
  1077. LUIOut(L3, "Object type is MAPI_ABCONT");
  1078. // Call QueryInterface on the object
  1079. LUIOut(L3, "Calling QueryInterface on the returned object");
  1080. hr = (lpABCont->QueryInterface((REFIID)(IID_IABContainer), (VOID **) &lpABCont2));
  1081. if (HR_FAILED(hr)) {
  1082. LUIOut(L2, "QueryInterface on IID_IABContainer FAILED");
  1083. retval = FALSE;
  1084. goto out;
  1085. }
  1086. else LUIOut(L3, "QueryInterface on IID_IABContainer PASSED");
  1087. LUIOut(L3, "Trying to release the object QI returned");
  1088. if(lpABCont2) {
  1089. if ((LPUNKNOWN)(lpABCont2)->Release() <= 0)
  1090. LUIOut(L3, "QueryInterface returned a valid ptr and released succesfully");
  1091. else {
  1092. LUIOut(L2, "Release FAILED:returned a > zero ref count");
  1093. }
  1094. lpABCont2 = NULL;
  1095. }
  1096. else {
  1097. LUIOut(L2, "QueryInterface did not return a valid ptr");
  1098. retval = FALSE;
  1099. goto out;
  1100. }
  1101. out:
  1102. #ifdef PAB
  1103. if (lpEid)
  1104. MAPIFreeBuffer(lpEid);
  1105. if (lpEidPAB)
  1106. MAPIFreeBuffer(lpEidPAB);
  1107. if (lpSPropValueAddress)
  1108. MAPIFreeBuffer(lpSPropValueAddress);
  1109. if (lpSPropValueEntryID)
  1110. MAPIFreeBuffer(lpSPropValueEntryID);
  1111. if (lpSPropValueDL)
  1112. MAPIFreeBuffer(lpSPropValueDL);
  1113. #endif
  1114. #ifdef WAB
  1115. if (lpEid)
  1116. lpWABObject->FreeBuffer(lpEid);
  1117. if (lpEidPAB)
  1118. lpWABObject->FreeBuffer(lpEidPAB);
  1119. if (lpSPropValueAddress)
  1120. lpWABObject->FreeBuffer(lpSPropValueAddress);
  1121. if (lpSPropValueEntryID)
  1122. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  1123. if (lpSPropValueDL)
  1124. lpWABObject->FreeBuffer(lpSPropValueDL);
  1125. #endif
  1126. if (lpAddress)
  1127. lpAddress->Release();
  1128. if (lpContentsTable)
  1129. lpContentsTable->Release();
  1130. if (lpABCont)
  1131. lpABCont->Release();
  1132. if (lpDLCont)
  1133. lpDLCont->Release();
  1134. if (lpAdrBook)
  1135. lpAdrBook->Release();
  1136. #ifdef PAB
  1137. if (lpMAPISession)
  1138. lpMAPISession->Release();
  1139. MAPIUninitialize();
  1140. #endif
  1141. #ifdef WAB
  1142. if (lpWABObject)
  1143. lpWABObject->Release();
  1144. #endif
  1145. return retval;
  1146. }
  1147. BOOL PAB_IABContainerCreateEntry()
  1148. {
  1149. //DWORD nCells, counter;
  1150. ULONG ulFlags = 0;
  1151. HRESULT hr = hrSuccess;
  1152. SCODE sc = SUCCESS_SUCCESS;
  1153. int retval=TRUE;
  1154. LPADRBOOK lpAdrBook = NULL;
  1155. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  1156. LPABCONT lpPABCont= NULL,lpPABCont2= NULL;
  1157. LPABCONT lpDLCont= NULL;
  1158. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  1159. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  1160. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  1161. ULONG cbEid=0; // entry id of the entry being added
  1162. LPENTRYID lpEid=NULL;
  1163. ULONG cValues = 0, ulObjType=NULL;
  1164. ULONG cRows = 0;
  1165. ULONG iEntry = 0;
  1166. int i=0,k=0;
  1167. LPMAILUSER lpAddress=NULL,lpAddress2=NULL,lpAddress3=NULL,lpAddress4=NULL;
  1168. LPMAPITABLE lpContentsTable = NULL;
  1169. LPSRowSet lpRowSet = NULL;
  1170. SPropValue PropValue[3] = {0}; // This value is 3 because we
  1171. // will be setting 3 properties:
  1172. // EmailAddress, DisplayName and
  1173. // AddressType.
  1174. SizedSPropTagArray(2, Cols) = { 2, {PR_OBJECT_TYPE, PR_ENTRYID } };
  1175. LPSPropValue lpSPropValueAddress = NULL;
  1176. LPSPropValue lpSPropValueEntryID = NULL;
  1177. LPSPropValue lpSPropValueDL = NULL;
  1178. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  1179. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  1180. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  1181. LUIOut(L1," ");
  1182. LUIOut(L1,"Running PAB_IABContainerCreateEntry");
  1183. LUIOut(L2,"-> Verifies IABContainer->CreateEntry is functional by performing the following:");
  1184. LUIOut(L2, " Attempts to CreateEntry with the MailUser template and checks...");
  1185. LUIOut(L2, " # The return code from CreateEntry");
  1186. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1187. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1188. LUIOut(L2, " count is tested for <= 0 (pass)");
  1189. LUIOut(L2, " Attempts to CreateEntry with the DistList template and checks...");
  1190. LUIOut(L2, " # The return code from CreateEntry");
  1191. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1192. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1193. LUIOut(L2, " count is tested for <= 0 (pass)");
  1194. LUIOut(L1," ");
  1195. if (!GetAB(OUT &lpAdrBook)) {
  1196. retval = FALSE;
  1197. goto out;
  1198. }
  1199. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  1200. assert(lpAdrBook != NULL);
  1201. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  1202. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  1203. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  1204. if (HR_FAILED(hr)) {
  1205. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  1206. retval=FALSE;
  1207. goto out;
  1208. }
  1209. //
  1210. // Try to create a MailUser entry in the container
  1211. //
  1212. LUIOut(L2, "Creating a Mail User in the container");
  1213. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  1214. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  1215. assert(lpABCont != NULL);
  1216. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  1217. IN 0, //Flags
  1218. OUT &cValues,
  1219. OUT &lpSPropValueAddress);
  1220. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  1221. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  1222. retval=FALSE;
  1223. goto out;
  1224. }
  1225. // The returned value of PR_DEF_CREATE_MAILUSER is an
  1226. // EntryID which can be passed to CreateEntry
  1227. //
  1228. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  1229. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  1230. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  1231. IN 0,
  1232. OUT (LPMAPIPROP *) &lpAddress);
  1233. if (HR_FAILED(hr)) {
  1234. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  1235. retval=FALSE;
  1236. goto out;
  1237. }
  1238. // Call QueryInterface on the object
  1239. hr = (lpAddress->QueryInterface((REFIID)(IID_IMailUser), (VOID **) &lpAddress2));
  1240. if (HR_FAILED(hr)) {
  1241. LUIOut(L2, "QueryInterface on IID_IMailUser FAILED");
  1242. retval = FALSE;
  1243. goto out;
  1244. }
  1245. else LUIOut(L2, "QueryInterface on IID_IMailUser PASSED");
  1246. if(lpAddress2) {
  1247. if ((LPUNKNOWN)(lpAddress2)->Release() <= 0)
  1248. LUIOut(L2, "QueryInterface returned a valid ptr and released succesfully");
  1249. else {
  1250. LUIOut(L2, "Release FAILED:returned a > zero ref count");
  1251. }
  1252. lpAddress2 = NULL;
  1253. }
  1254. else {
  1255. LUIOut(L2, "QueryInterface did not return a valid ptr");
  1256. retval = FALSE;
  1257. goto out;
  1258. }
  1259. #ifdef DISTLIST
  1260. //
  1261. // Try to create a DL entry in the container
  1262. //
  1263. LUIOut(L2, "Creating a Distribution List in the container");
  1264. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_DL property");
  1265. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_DL
  1266. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  1267. IN 0, //Flags
  1268. OUT &cValues,
  1269. OUT &lpSPropValueDL);
  1270. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  1271. LUIOut(L3,"GetProps failed for Default DL template");
  1272. retval=FALSE;
  1273. goto out;
  1274. }
  1275. // The returned value of PR_DEF_CREATE_DL is an
  1276. // EntryID which one can pass to CreateEntry
  1277. //
  1278. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  1279. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  1280. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  1281. IN 0,
  1282. OUT (LPMAPIPROP *) &lpAddress3);
  1283. if (HR_FAILED(hr)) {
  1284. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  1285. retval=FALSE;
  1286. goto out;
  1287. }
  1288. // Call QueryInterface on the object
  1289. hr = (lpAddress3->QueryInterface((REFIID)(IID_IDistList), (VOID **) &lpAddress4));
  1290. if (HR_FAILED(hr)) {
  1291. LUIOut(L2, "QueryInterface on IID_IDistList FAILED");
  1292. retval = FALSE;
  1293. goto out;
  1294. }
  1295. else LUIOut(L2, "QueryInterface on IID_IDistList PASSED");
  1296. if(lpAddress4) {
  1297. if ((LPUNKNOWN)(lpAddress4)->Release() <= 0)
  1298. LUIOut(L2, "QueryInterface returned a valid ptr and released succesfully");
  1299. else {
  1300. LUIOut(L2, "Release FAILED:returned a > zero ref count");
  1301. }
  1302. lpAddress4 = NULL;
  1303. }
  1304. else {
  1305. LUIOut(L2, "QueryInterface did not return a valid ptr");
  1306. retval = FALSE;
  1307. goto out;
  1308. }
  1309. #endif
  1310. out:
  1311. #ifdef PAB
  1312. if (lpEid)
  1313. MAPIFreeBuffer(lpEid);
  1314. if (lpEidPAB)
  1315. MAPIFreeBuffer(lpEidPAB);
  1316. if (lpSPropValueAddress)
  1317. MAPIFreeBuffer(lpSPropValueAddress);
  1318. if (lpSPropValueEntryID)
  1319. MAPIFreeBuffer(lpSPropValueEntryID);
  1320. if (lpSPropValueDL)
  1321. MAPIFreeBuffer(lpSPropValueDL);
  1322. #endif
  1323. #ifdef WAB
  1324. if (lpEid)
  1325. lpWABObject->FreeBuffer(lpEid);
  1326. if (lpEidPAB)
  1327. lpWABObject->FreeBuffer(lpEidPAB);
  1328. if (lpSPropValueAddress)
  1329. lpWABObject->FreeBuffer(lpSPropValueAddress);
  1330. if (lpSPropValueEntryID)
  1331. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  1332. if (lpSPropValueDL)
  1333. lpWABObject->FreeBuffer(lpSPropValueDL);
  1334. #endif
  1335. if (lpAddress)
  1336. lpAddress->Release();
  1337. if (lpAddress2)
  1338. lpAddress2->Release();
  1339. if (lpAddress3)
  1340. lpAddress3->Release();
  1341. if (lpAddress4)
  1342. lpAddress4->Release();
  1343. if (lpContentsTable)
  1344. lpContentsTable->Release();
  1345. if (lpPABCont)
  1346. lpPABCont->Release();
  1347. if (lpABCont)
  1348. lpABCont->Release();
  1349. if (lpDLCont)
  1350. lpDLCont->Release();
  1351. if (lpAdrBook)
  1352. lpAdrBook->Release();
  1353. #ifdef PAB
  1354. if (lpMAPISession)
  1355. lpMAPISession->Release();
  1356. MAPIUninitialize();
  1357. #endif
  1358. #ifdef WAB
  1359. if (lpWABObject)
  1360. lpWABObject->Release();
  1361. #endif
  1362. return retval;
  1363. }
  1364. BOOL PAB_IDLSuite()
  1365. {
  1366. BOOL Cleanup;
  1367. HRESULT hr = hrSuccess;
  1368. int retval=TRUE;
  1369. ULONG cbEidPAB = 0;
  1370. ULONG cbEid=0; // entry id of the entry being added
  1371. ULONG cValues = 0, ulObjType=NULL, cValues2;
  1372. ULONG cRows = 0;
  1373. UINT Entry, DL, NumEntries, NumDLs, PropIndex;
  1374. char szDLTag[SML_BUF], *lpszDisplayName = NULL, *lpszReturnName = NULL;
  1375. EntryID *lpEntries, *lpDLs;
  1376. char EntryBuf[MAX_BUF];
  1377. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  1378. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  1379. LPADRBOOK lpAdrBook= NULL;
  1380. LPABCONT lpABCont= NULL;
  1381. LPMAILUSER lpMailUser=NULL;
  1382. LPDISTLIST lpDL=NULL,lpDL2=NULL;
  1383. LPMAPITABLE lpTable = NULL;
  1384. LPSRowSet lpRows = NULL;
  1385. SRestriction Restriction;
  1386. SPropValue *lpPropValue = NULL; //Used to create props for the mailusers
  1387. SPropValue PropValue[1]= {0}; //
  1388. LPSPropValue lpSPropValueAddress = NULL; //Used to create default mailuser
  1389. LPSPropValue lpSPropValueEntryID = NULL; //Used to getprops on entryid of user
  1390. LPSPropValue lpSPropValueDL = NULL; //Used to create default DL
  1391. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  1392. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  1393. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  1394. LUIOut(L1," ");
  1395. LUIOut(L1,"Running PAB_IDLSuite");
  1396. LUIOut(L2,"-> Tests Distribution List functionality by performing the following:");
  1397. LUIOut(L2, " Attempts to CreateEntry with the DistList template and checks...");
  1398. LUIOut(L2, " # The return code from CreateEntry");
  1399. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1400. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1401. LUIOut(L2, " count is tested for <= 0 (pass)");
  1402. LUIOut(L2, " Calls CreateEntry on the DistList object to add MailUser and DL members and checks...");
  1403. LUIOut(L2, " # The return code from CreateEntry");
  1404. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1405. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1406. LUIOut(L2, " count is tested for <= 0 (pass)");
  1407. LUIOut(L1," ");
  1408. if (!GetAB(OUT &lpAdrBook)) {
  1409. retval = FALSE;
  1410. goto out;
  1411. }
  1412. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  1413. assert(lpAdrBook != NULL);
  1414. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  1415. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  1416. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  1417. if (HR_FAILED(hr)) {
  1418. LUIOut(L3,"IAddrBook->OpenEntry Failed");
  1419. retval=FALSE;
  1420. goto out;
  1421. }
  1422. //
  1423. // Create MailUsers in the container
  1424. //
  1425. LUIOut(L2, "Creating MailUsers");
  1426. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  1427. assert(lpABCont != NULL);
  1428. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  1429. IN 0, //Flags
  1430. OUT &cValues,
  1431. OUT &lpSPropValueAddress);
  1432. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  1433. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  1434. retval=FALSE;
  1435. goto out;
  1436. }
  1437. // The returned value of PR_DEF_CREATE_MAILUSER is an
  1438. // EntryID which can be passed to CreateEntry
  1439. //
  1440. // Retrieve user info from ini file
  1441. lstrcpy(szDLTag,"Address1");
  1442. GetPrivateProfileString("DLTestSuite",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  1443. //_itoa(0,(char*)lpszDisplayName[strlen(lpszDisplayName)],10);
  1444. NumEntries = GetPrivateProfileInt("DLTestSuite","NumCopies",0,INIFILENAME);
  1445. //Allocate an array of String pointers to hold the EntryIDs
  1446. lpEntries = (EntryID*)LocalAlloc(LMEM_FIXED, NumEntries * sizeof(EntryID));
  1447. lpszDisplayName = (char*)LocalAlloc(LMEM_FIXED, MAX_BUF);
  1448. ParseIniBuffer(IN EntryBuf, IN 1, OUT lpszDisplayName);
  1449. for (Entry = 0; Entry < NumEntries; Entry++) {
  1450. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  1451. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  1452. IN 0,
  1453. OUT (LPMAPIPROP *) &lpMailUser);
  1454. if (HR_FAILED(hr)) {
  1455. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  1456. retval=FALSE;
  1457. goto out;
  1458. }
  1459. //
  1460. // Then set the properties
  1461. //
  1462. CreateProps(IN INIFILENAME, IN "Properties", OUT &lpPropValue, OUT &cValues2, IN Entry, IN &lpszDisplayName, OUT &lpszReturnName);
  1463. LUIOut(L3,"MailUser Entry to Add: %s",lpszReturnName);
  1464. hr = lpMailUser->SetProps(IN cValues2,
  1465. IN lpPropValue,
  1466. IN NULL);
  1467. if (HR_FAILED(hr)) {
  1468. LUIOut(L3,"MailUser->SetProps call FAILED with 0x%x",hr);
  1469. retval=FALSE;
  1470. goto out;
  1471. }
  1472. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  1473. if (HR_FAILED(hr)) {
  1474. LUIOut(L3,"MailUser->SaveChanges FAILED");
  1475. retval=FALSE;
  1476. goto out;
  1477. }
  1478. // Store the EID for deleting this entry later
  1479. hr = lpMailUser->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  1480. IN 0, //Flags
  1481. OUT &cValues,
  1482. OUT &lpSPropValueEntryID);
  1483. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  1484. LUIOut(L3,"GetProps FAILED for MailUser");
  1485. retval=FALSE;
  1486. goto out;
  1487. }
  1488. //Allocate space for the display name
  1489. lpEntries[Entry].lpDisplayName = (char*)LocalAlloc(LMEM_FIXED, (strlen(lpszReturnName)+1));
  1490. //Copy the DisplayName for use later
  1491. strcpy(lpEntries[Entry].lpDisplayName, lpszReturnName);
  1492. //Allocate space for the EID (lpb)
  1493. lpEntries[Entry].lpb = (LPBYTE)LocalAlloc(LMEM_FIXED, lpSPropValueEntryID->Value.bin.cb);
  1494. //Copy the EID for use later
  1495. lpEntries[Entry].cb = lpSPropValueEntryID->Value.bin.cb;
  1496. memcpy(lpEntries[Entry].lpb,lpSPropValueEntryID->Value.bin.lpb,
  1497. lpEntries[Entry].cb);
  1498. //Free the SPropValue for use in the next loop
  1499. if (lpPropValue) {
  1500. for (unsigned int Prop = 0; Prop < cValues2; Prop++) {
  1501. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_STRING8) {
  1502. if (lpPropValue[Prop].Value.LPSZ) {
  1503. LocalFree(lpPropValue[Prop].Value.LPSZ);
  1504. lpPropValue[Prop].Value.LPSZ = NULL;
  1505. }
  1506. }
  1507. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_BINARY) {
  1508. if (lpPropValue[Prop].Value.bin.lpb) {
  1509. LocalFree(lpPropValue[Prop].Value.bin.lpb);
  1510. lpPropValue[Prop].Value.bin.lpb = NULL;
  1511. }
  1512. }
  1513. }
  1514. LocalFree(lpPropValue);
  1515. lpPropValue=NULL;
  1516. }
  1517. if (lpSPropValueEntryID) {
  1518. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  1519. lpSPropValueEntryID = NULL;
  1520. }
  1521. lpMailUser->Release();
  1522. lpMailUser = NULL;
  1523. }
  1524. //
  1525. // Create the Distribution Lists in the container
  1526. //
  1527. NumDLs = GetPrivateProfileInt("DLTestSuite","NumDLs",0,INIFILENAME);
  1528. lpDLs = (EntryID*)LocalAlloc(LMEM_FIXED, NumDLs * sizeof(EntryID));
  1529. LUIOut(L2, "Creating Distribution Lists");
  1530. for (DL = 0; DL < NumDLs; DL++) {
  1531. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  1532. IN 0, //Flags
  1533. OUT &cValues,
  1534. OUT &lpSPropValueDL);
  1535. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  1536. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  1537. retval=FALSE;
  1538. goto out;
  1539. }
  1540. // The returned value of PR_DEF_CREATE_DL is an
  1541. // EntryID which can be passed to CreateEntry
  1542. //
  1543. //LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  1544. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  1545. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  1546. IN 0,
  1547. OUT (LPMAPIPROP *) &lpDL);
  1548. if (HR_FAILED(hr)) {
  1549. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  1550. retval=FALSE;
  1551. goto out;
  1552. }
  1553. // Call QueryInterface on the object
  1554. hr = (lpDL->QueryInterface((REFIID)(IID_IDistList), (VOID **) &lpDL2));
  1555. if (HR_FAILED(hr)) {
  1556. LUIOut(L4, "QueryInterface on IID_IDistList FAILED. hr = 0x%x", hr);
  1557. retval = FALSE;
  1558. goto out;
  1559. }
  1560. else LUIOut(L4, "QueryInterface on IID_IDistList PASSED");
  1561. lstrcpy(szDLTag,"DistList1");
  1562. GetPrivateProfileString("DLTestSuite",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  1563. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  1564. //StrLen2 = (StrLen1 + sprintf((char*)&EntProp[0][StrLen1], " [Thread #%i] - ", *(int *)lpThreadNum));
  1565. _itoa(DL,(char*)&EntryBuf[strlen(EntryBuf)],10);
  1566. LUIOut(L3,"DistList Entry to Add: %s",EntryBuf);
  1567. cValues = 1;
  1568. PropValue[0].Value.LPSZ = (LPTSTR)EntryBuf;
  1569. hr = lpDL->SetProps(IN cValues,
  1570. IN PropValue,
  1571. IN NULL);
  1572. if (HR_FAILED(hr)) {
  1573. LUIOut(L3,"DL->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  1574. retval=FALSE;
  1575. goto out;
  1576. }
  1577. hr = lpDL->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  1578. if (HR_FAILED(hr)) {
  1579. LUIOut(L3,"DL->SaveChanges FAILED");
  1580. retval=FALSE;
  1581. goto out;
  1582. }
  1583. // Want a container interface to the DL, and since QueryInterface on a DL
  1584. // is currently broken (returns a MailUser interface when called with IID_IDistList)
  1585. // we do it the hard way. Call GetProps to get the EID for the new DL, and then
  1586. // call OpenEntry from the container or AB interfaces to open a DL interface
  1587. hr = lpDL->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  1588. IN 0, //Flags
  1589. OUT &cValues,
  1590. OUT &lpSPropValueEntryID);
  1591. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  1592. LUIOut(L3,"GetProps FAILED for MailUser");
  1593. retval=FALSE;
  1594. goto out;
  1595. }
  1596. lpDL2->Release(); //Free up this pointer so we can recycle it
  1597. hr = lpABCont->OpenEntry(IN lpSPropValueEntryID->Value.bin.cb,
  1598. IN (LPENTRYID) lpSPropValueEntryID->Value.bin.lpb,
  1599. IN &IID_IDistList,
  1600. IN MAPI_BEST_ACCESS,
  1601. OUT &ulObjType,
  1602. OUT (LPUNKNOWN*) &lpDL2);
  1603. if (HR_FAILED(hr)) {
  1604. LUIOut(L3,"OpenEntry failed for DistList");
  1605. retval=FALSE;
  1606. goto out;
  1607. }
  1608. LUIOut(L3, "Adding MailUser Members to the Distribution List");
  1609. //
  1610. // Now add mailuser entries to the DL
  1611. //
  1612. for (Entry = 0; Entry < NumEntries; Entry++) {
  1613. hr = lpDL2->CreateEntry( IN lpEntries[Entry].cb,
  1614. IN (LPENTRYID) lpEntries[Entry].lpb,
  1615. IN 0,
  1616. OUT (LPMAPIPROP *) &lpMailUser);
  1617. if (HR_FAILED(hr)) {
  1618. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  1619. retval=FALSE;
  1620. goto out;
  1621. }
  1622. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  1623. if (HR_FAILED(hr)) {
  1624. LUIOut(L3,"MailUser->SaveChanges FAILED");
  1625. retval=FALSE;
  1626. goto out;
  1627. }
  1628. lpMailUser->Release();
  1629. lpMailUser = NULL;
  1630. }
  1631. //Allocate space for the display name
  1632. lpDLs[DL].lpDisplayName = (char*)LocalAlloc(LMEM_FIXED, (strlen(EntryBuf)+1));
  1633. //Copy the DisplayName for use later
  1634. strcpy(lpDLs[DL].lpDisplayName, EntryBuf);
  1635. //Allocate space for the EID (lpb)
  1636. lpDLs[DL].lpb = (LPBYTE)LocalAlloc(LMEM_FIXED, lpSPropValueEntryID->Value.bin.cb);
  1637. //Copy the EID for use later
  1638. lpDLs[DL].cb = lpSPropValueEntryID->Value.bin.cb;
  1639. memcpy(lpDLs[DL].lpb,lpSPropValueEntryID->Value.bin.lpb,
  1640. lpDLs[DL].cb);
  1641. if (lpSPropValueEntryID) {
  1642. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  1643. lpSPropValueEntryID = NULL;
  1644. }
  1645. if (lpSPropValueDL) {
  1646. lpWABObject->FreeBuffer(lpSPropValueDL);
  1647. lpSPropValueDL = NULL;
  1648. }
  1649. lpDL->Release();
  1650. lpDL = NULL;
  1651. lpDL2->Release();
  1652. lpDL2 = NULL;
  1653. }
  1654. //
  1655. // Verify all entries are in the DL
  1656. //
  1657. LUIOut(L2, "Verifying MailUser Members are in the Distribution List");
  1658. for (DL = 0; DL < NumDLs; DL++) {
  1659. // Need to get an interface to the DL
  1660. hr = lpABCont->OpenEntry(IN lpDLs[DL].cb,
  1661. IN (LPENTRYID) lpDLs[DL].lpb,
  1662. IN &IID_IDistList,
  1663. IN MAPI_BEST_ACCESS,
  1664. OUT &ulObjType,
  1665. OUT (LPUNKNOWN*) &lpDL);
  1666. if (HR_FAILED(hr)) {
  1667. LUIOut(L3,"OpenEntry failed for DistList");
  1668. retval=FALSE;
  1669. goto out;
  1670. }
  1671. // Create a contents table to verify each added entry exists in the DL
  1672. hr = lpDL->GetContentsTable(ULONG(0), &lpTable);
  1673. if (HR_FAILED(hr)) {
  1674. LUIOut(L3,"DistList->GetContentsTable call FAILED, returned 0x%x", hr);
  1675. retval=FALSE;
  1676. goto out;
  1677. }
  1678. // Allocate the SpropValue ptr in the restriction structure
  1679. lpWABObject->AllocateBuffer(sizeof(SPropValue), (void**)&(Restriction.res.resProperty.lpProp));
  1680. Restriction.res.resProperty.lpProp = (SPropValue*)Restriction.res.resProperty.lpProp;
  1681. for (Entry = 0; Entry < NumEntries; Entry++) {
  1682. hr = lpDL->OpenEntry( IN lpEntries[Entry].cb,
  1683. IN (LPENTRYID) lpEntries[Entry].lpb,
  1684. IN &IID_IMailUser,
  1685. IN MAPI_BEST_ACCESS,
  1686. OUT &ulObjType,
  1687. OUT (LPUNKNOWN*) &lpMailUser);
  1688. if (HR_FAILED(hr)) {
  1689. LUIOut(L3,"OpenEntry failed for DistList");
  1690. retval=FALSE;
  1691. goto out;
  1692. }
  1693. lpMailUser->Release();
  1694. lpMailUser = NULL;
  1695. // Build the restriction structure to pass to lpTable->Restrict
  1696. //** For testing the fail case only, stub out for real testing
  1697. // lstrcpy(lpszDisplayNames[Counter2], "This should not match");
  1698. //**
  1699. Restriction.rt = RES_PROPERTY; //Property restriction
  1700. Restriction.res.resProperty.relop = RELOP_EQ; //Equals
  1701. Restriction.res.resProperty.ulPropTag = PR_DISPLAY_NAME;
  1702. Restriction.res.resProperty.lpProp->ulPropTag = PR_DISPLAY_NAME;
  1703. Restriction.res.resProperty.lpProp->Value.LPSZ = lpEntries[Entry].lpDisplayName;
  1704. hr = lpTable->Restrict(&Restriction, ULONG(0));
  1705. if (HR_FAILED(hr)) {
  1706. LUIOut(L3,"Table->Restrict call FAILED, returned 0x%x", hr);
  1707. retval=FALSE;
  1708. goto out;
  1709. }
  1710. hr = lpTable->QueryRows(LONG(1),
  1711. ULONG(0),
  1712. &lpRows);
  1713. if (HR_FAILED(hr)) {
  1714. LUIOut(L3,"Table->QueryRows call FAILED: Entry #%i, returned 0x%x", Entry, hr);
  1715. retval=FALSE;
  1716. goto out;
  1717. }
  1718. if (!lpRows->cRows) {
  1719. LUIOut(L2, "QueryRows did not find entry #%i. Test FAILED", Entry);
  1720. retval=FALSE;
  1721. goto out;
  1722. }
  1723. //** For testing purposes only, stub out for real testing
  1724. //InitializeCriticalSection(&CriticalSection);
  1725. //EnterCriticalSection(&CriticalSection);
  1726. //DisplayRows(lpRows);
  1727. //LeaveCriticalSection(&CriticalSection);
  1728. //**
  1729. // Does the user want us to cleanup after ourself?
  1730. Cleanup = GetPrivateProfileInt("DLTestSuite","Cleanup",1,INIFILENAME);
  1731. if (Cleanup) {
  1732. // Change the EntryID to a LPENTRYLIST
  1733. FindPropinRow(&lpRows->aRow[0],
  1734. PR_ENTRYID,
  1735. &PropIndex);
  1736. hr = HrCreateEntryListFromID(lpWABObject,
  1737. IN lpRows->aRow[0].lpProps[PropIndex].Value.bin.cb,
  1738. IN (ENTRYID*)lpRows->aRow[0].lpProps[PropIndex].Value.bin.lpb,
  1739. OUT &lpEntryList);
  1740. if (HR_FAILED(hr)) {
  1741. LUIOut(L3,"Could not Create Entry List");
  1742. retval=FALSE;
  1743. goto out;
  1744. }
  1745. // Then pass the lpEntryList to DeleteEntries to delete ...
  1746. hr = lpDL->DeleteEntries(IN lpEntryList,IN 0);
  1747. if (HR_FAILED(hr)) {
  1748. LUIOut(L3,"Could not Delete Entry %i. DeleteEntry returned 0x%x", Entry, hr);
  1749. FreeEntryList(lpWABObject, &lpEntryList);
  1750. retval=FALSE;
  1751. goto out;
  1752. }
  1753. FreeRows(lpWABObject, &lpRows); // Cleanup from first call to queryrows
  1754. // Verify the entry was deleted by calling QueryRows again
  1755. hr = lpTable->QueryRows(LONG(1),
  1756. ULONG(0),
  1757. &lpRows);
  1758. if (HR_FAILED(hr)) {
  1759. LUIOut(L3,"Table->QueryRows call FAILED: Entry #%i, returned 0x%x", Entry, hr);
  1760. retval=FALSE;
  1761. goto out;
  1762. }
  1763. if (lpRows->cRows) { // Should be 0 if deleted
  1764. LUIOut(L2, "QueryRows found entry #%i even tho it was deleted. Test FAILED", Entry);
  1765. retval=FALSE;
  1766. goto out;
  1767. }
  1768. }
  1769. //Cleanup
  1770. FreeRows(lpWABObject, &lpRows); // Cleanup from second call to queryrows
  1771. if (lpEntryList) {
  1772. FreeEntryList(lpWABObject, &lpEntryList);
  1773. lpEntryList = NULL;
  1774. }
  1775. }
  1776. LUIOut(L3, "All members verified for Distribution List #%i", DL);
  1777. //Free up memory
  1778. lpWABObject->FreeBuffer(Restriction.res.resProperty.lpProp);
  1779. if (lpTable) {
  1780. lpTable->Release();
  1781. lpTable = NULL;
  1782. }
  1783. lpDL->Release();
  1784. lpDL = NULL;
  1785. }
  1786. //
  1787. // Cleanup the WAB
  1788. //
  1789. if (Cleanup) {
  1790. LUIOut(L2, "Cleanup: Removing MailUsers");
  1791. // First, delete the MailUser entries from the wab
  1792. for (Entry = 0; Entry < NumEntries; Entry++) {
  1793. hr = HrCreateEntryListFromID(lpWABObject,
  1794. IN lpEntries[Entry].cb,
  1795. IN (ENTRYID*)lpEntries[Entry].lpb,
  1796. OUT &lpEntryList);
  1797. if (HR_FAILED(hr)) {
  1798. LUIOut(L3,"Could not Create Entry List");
  1799. retval=FALSE;
  1800. goto out;
  1801. }
  1802. // Then pass the lpEntryList to DeleteEntries to delete ...
  1803. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  1804. if (HR_FAILED(hr)) {
  1805. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  1806. FreeEntryList(lpWABObject, &lpEntryList);
  1807. retval=FALSE;
  1808. goto out;
  1809. }
  1810. LocalFree((HLOCAL)lpEntries[Entry].lpDisplayName);
  1811. LocalFree((HLOCAL)lpEntries[Entry].lpb);
  1812. FreeEntryList(lpWABObject, &lpEntryList);
  1813. }
  1814. LocalFree((HLOCAL)lpEntries);
  1815. LUIOut(L2, "Cleanup: Removing Distribution Lists");
  1816. // Now, delete the Distribution Lists from the wab
  1817. for (DL = 0; DL < NumDLs; DL++) {
  1818. hr = HrCreateEntryListFromID(lpWABObject,
  1819. IN lpDLs[DL].cb,
  1820. IN (ENTRYID*)lpDLs[DL].lpb,
  1821. OUT &lpEntryList);
  1822. if (HR_FAILED(hr)) {
  1823. LUIOut(L3,"Could not Create Entry List");
  1824. retval=FALSE;
  1825. goto out;
  1826. }
  1827. // Then pass the lpEntryList to DeleteEntries to delete ...
  1828. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  1829. if (HR_FAILED(hr)) {
  1830. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  1831. FreeEntryList(lpWABObject, &lpEntryList);
  1832. retval=FALSE;
  1833. goto out;
  1834. }
  1835. LocalFree((HLOCAL)lpDLs[DL].lpDisplayName);
  1836. LocalFree((HLOCAL)lpDLs[DL].lpb);
  1837. FreeEntryList(lpWABObject, &lpEntryList);
  1838. }
  1839. LocalFree((HLOCAL)lpDLs);
  1840. }
  1841. else {
  1842. LUIOut(L2, "Cleanup: User has requested that the MailUser entries and DistLists not be removed");
  1843. for (Entry = 0; Entry < NumEntries; Entry++) {
  1844. LocalFree((HLOCAL)lpEntries[Entry].lpDisplayName);
  1845. LocalFree((HLOCAL)lpEntries[Entry].lpb);
  1846. }
  1847. LocalFree((HLOCAL)lpEntries);
  1848. for (DL = 0; DL < NumDLs; DL++) {
  1849. LocalFree((HLOCAL)lpDLs[DL].lpDisplayName);
  1850. LocalFree((HLOCAL)lpDLs[DL].lpb);
  1851. }
  1852. LocalFree((HLOCAL)lpDLs);
  1853. }
  1854. out:
  1855. #ifdef PAB
  1856. if (lpEidPAB)
  1857. MAPIFreeBuffer(lpEidPAB);
  1858. if (lpSPropValueAddress)
  1859. MAPIFreeBuffer(lpSPropValueAddress);
  1860. if (lpSPropValueEntryID)
  1861. MAPIFreeBuffer(lpSPropValueEntryID);
  1862. if (lpSPropValueDL)
  1863. MAPIFreeBuffer(lpSPropValueDL);
  1864. #endif
  1865. #ifdef WAB
  1866. if (lpEidPAB)
  1867. lpWABObject->FreeBuffer(lpEidPAB);
  1868. if (lpSPropValueAddress)
  1869. lpWABObject->FreeBuffer(lpSPropValueAddress);
  1870. if (lpSPropValueEntryID)
  1871. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  1872. if (lpSPropValueDL)
  1873. lpWABObject->FreeBuffer(lpSPropValueDL);
  1874. #endif
  1875. //if (lpszDisplayName) LocalFree(lpszDisplayName);
  1876. if (lpMailUser)
  1877. lpMailUser->Release();
  1878. if (lpDL)
  1879. lpDL->Release();
  1880. if (lpDL2)
  1881. lpDL2->Release();
  1882. if (lpTable)
  1883. lpTable->Release();
  1884. if (lpABCont)
  1885. lpABCont->Release();
  1886. if (lpAdrBook)
  1887. lpAdrBook->Release();
  1888. #ifdef PAB
  1889. if (lpMAPISession)
  1890. lpMAPISession->Release();
  1891. MAPIUninitialize();
  1892. #endif
  1893. #ifdef WAB
  1894. if (lpWABObject)
  1895. lpWABObject->Release();
  1896. #endif
  1897. return retval;
  1898. }
  1899. BOOL NamedPropsSuite()
  1900. {
  1901. BOOL Cleanup;
  1902. HRESULT hr = hrSuccess;
  1903. int retval=TRUE;
  1904. ULONG cbEidPAB = 0;
  1905. ULONG cbEid=0; // entry id of the entry being added
  1906. ULONG cValues = 0, ulObjType=NULL, cValues2;
  1907. ULONG cRows = 0;
  1908. UINT Entry, DL, NumEntries, NumDLs, PropIndex;
  1909. char szDLTag[SML_BUF], *lpszDisplayName = NULL, *lpszReturnName = NULL;
  1910. EntryID *lpEntries, *lpDLs;
  1911. char EntryBuf[MAX_BUF];
  1912. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  1913. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  1914. LPADRBOOK lpAdrBook= NULL;
  1915. LPABCONT lpABCont= NULL;
  1916. LPMAILUSER lpMailUser=NULL;
  1917. LPDISTLIST lpDL=NULL,lpDL2=NULL;
  1918. LPMAPITABLE lpTable = NULL;
  1919. LPSRowSet lpRows = NULL;
  1920. SRestriction Restriction;
  1921. SPropValue *lpPropValue = NULL; //Used to create props for the mailusers
  1922. SPropValue PropValue[1]= {0}; //
  1923. LPSPropValue lpSPropValueAddress = NULL; //Used to create default mailuser
  1924. LPSPropValue lpSPropValueEntryID = NULL; //Used to getprops on entryid of user
  1925. LPSPropValue lpSPropValueDL = NULL; //Used to create default DL
  1926. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  1927. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  1928. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  1929. MAPINAMEID mnid[3];
  1930. LPMAPINAMEID lpmnid = &(mnid[0]);
  1931. LPSPropTagArray lpNamedPropTags = NULL;
  1932. SPropValue spv[3];
  1933. /* LUIOut(L1," ");
  1934. LUIOut(L1,"Running PAB_IDLSuite");
  1935. LUIOut(L2,"-> Tests Distribution List functionality by performing the following:");
  1936. LUIOut(L2, " Attempts to CreateEntry with the DistList template and checks...");
  1937. LUIOut(L2, " # The return code from CreateEntry");
  1938. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1939. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1940. LUIOut(L2, " count is tested for <= 0 (pass)");
  1941. LUIOut(L2, " Calls CreateEntry on the DistList object to add MailUser and DL members and checks...");
  1942. LUIOut(L2, " # The return code from CreateEntry");
  1943. LUIOut(L2, " # QueryInterface is called on the returned object and checked for success");
  1944. LUIOut(L2, " # Release is called on the interface ptr returned from QI and the reference");
  1945. LUIOut(L2, " count is tested for <= 0 (pass)");
  1946. */ LUIOut(L1," ");
  1947. if (!GetAB(OUT &lpAdrBook)) {
  1948. retval = FALSE;
  1949. goto out;
  1950. }
  1951. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  1952. assert(lpAdrBook != NULL);
  1953. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  1954. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  1955. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  1956. if (HR_FAILED(hr)) {
  1957. LUIOut(L3,"IAddrBook->OpenEntry Failed");
  1958. retval=FALSE;
  1959. goto out;
  1960. }
  1961. //
  1962. // Create MailUsers in the container
  1963. //
  1964. LUIOut(L2, "Creating MailUsers");
  1965. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  1966. assert(lpABCont != NULL);
  1967. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  1968. IN 0, //Flags
  1969. OUT &cValues,
  1970. OUT &lpSPropValueAddress);
  1971. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  1972. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  1973. retval=FALSE;
  1974. goto out;
  1975. }
  1976. // The returned value of PR_DEF_CREATE_MAILUSER is an
  1977. // EntryID which can be passed to CreateEntry
  1978. //
  1979. // Retrieve user info from ini file
  1980. lstrcpy(szDLTag,"Address1");
  1981. GetPrivateProfileString("NamedPropsTestSuite",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  1982. //_itoa(0,(char*)lpszDisplayName[strlen(lpszDisplayName)],10);
  1983. NumEntries = GetPrivateProfileInt("NamedPropsTestSuite","NumCopies",0,INIFILENAME);
  1984. //Allocate an array of String pointers to hold the EntryIDs
  1985. lpEntries = (EntryID*)LocalAlloc(LMEM_FIXED, NumEntries * sizeof(EntryID));
  1986. lpszDisplayName = (char*)LocalAlloc(LMEM_FIXED, MAX_BUF);
  1987. ParseIniBuffer(IN EntryBuf, IN 1, OUT lpszDisplayName);
  1988. for (Entry = 0; Entry < NumEntries; Entry++) {
  1989. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  1990. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  1991. IN 0,
  1992. OUT (LPMAPIPROP *) &lpMailUser);
  1993. if (HR_FAILED(hr)) {
  1994. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  1995. retval=FALSE;
  1996. goto out;
  1997. }
  1998. //
  1999. // Then set the properties
  2000. //
  2001. CreateProps(IN INIFILENAME, IN "Properties", OUT &lpPropValue, OUT &cValues2, IN Entry, IN &lpszDisplayName, OUT &lpszReturnName);
  2002. LUIOut(L3,"MailUser Entry to Add: %s",lpszReturnName);
  2003. hr = lpMailUser->SetProps(IN cValues2,
  2004. IN lpPropValue,
  2005. IN NULL);
  2006. if (HR_FAILED(hr)) {
  2007. LUIOut(L3,"MailUser->SetProps call FAILED with 0x%x",hr);
  2008. retval=FALSE;
  2009. goto out;
  2010. }
  2011. //
  2012. // Create and save 3 Named Properties
  2013. //
  2014. mnid[0].lpguid = &WabTestGUID;
  2015. mnid[0].ulKind = MNID_STRING; // This means union will contain a UNICODE string...
  2016. mnid[0].Kind.lpwstrName = L"A long test string of little meaning or relevance entered here ~!@#$%^&*{}[]()";
  2017. mnid[1].lpguid = &WabTestGUID;
  2018. mnid[1].ulKind = MNID_ID; // This means union will contain a long...
  2019. mnid[1].Kind.lID = 0x00000000; // numeric property 1
  2020. mnid[2].lpguid = &WabTestGUID;
  2021. mnid[2].ulKind = MNID_ID; // This means union will contain a long...
  2022. mnid[2].Kind.lID = 0xFFFFFFFF; // numeric property 1
  2023. hr = lpMailUser->GetIDsFromNames(3, // named props in the array
  2024. &lpmnid, // &-of because this is an array
  2025. MAPI_CREATE,
  2026. &lpNamedPropTags);
  2027. if (hr) {
  2028. //
  2029. // I'd really be suprised if I got S_OK for this...
  2030. //
  2031. if (GetScode(hr) != MAPI_W_ERRORS_RETURNED) {
  2032. // Real error here
  2033. retval = FALSE;
  2034. goto out;
  2035. }
  2036. // Basically, this means you don't have anything by this name and you
  2037. // didn't ask the object to create it.
  2038. //$ no biggie
  2039. }
  2040. LUIOut(L4, "GetIDsFromNames returned %i tags.", lpNamedPropTags->cValues);
  2041. //
  2042. // Ok, so what can I do with this ptaga? Well, we can set a value for it by doing:
  2043. //
  2044. spv[0].ulPropTag = CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[0],PT_STRING8);
  2045. spv[0].Value.lpszA = "More meaningless testing text of no consequence !@#$%&*()_+[]{}";
  2046. spv[1].ulPropTag = CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[1],PT_LONG);
  2047. spv[1].Value.l = 0x5A5A5A5A;
  2048. spv[2].ulPropTag = CHANGE_PROP_TYPE(lpNamedPropTags->aulPropTag[2],PT_BINARY);
  2049. GenerateRandomBinary(&(spv[2].Value.bin),256); // stick 256 bytes of random data in there
  2050. hr = lpMailUser->SetProps(
  2051. 3,
  2052. &spv[0],
  2053. NULL);
  2054. if (HR_FAILED(hr)) {
  2055. goto out;
  2056. }
  2057. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  2058. if (HR_FAILED(hr)) {
  2059. LUIOut(L3,"MailUser->SaveChanges FAILED");
  2060. retval=FALSE;
  2061. goto out;
  2062. }
  2063. // Store the EID for deleting this entry later
  2064. hr = lpMailUser->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  2065. IN 0, //Flags
  2066. OUT &cValues,
  2067. OUT &lpSPropValueEntryID);
  2068. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  2069. LUIOut(L3,"GetProps FAILED for MailUser");
  2070. retval=FALSE;
  2071. goto out;
  2072. }
  2073. //Allocate space for the display name
  2074. lpEntries[Entry].lpDisplayName = (char*)LocalAlloc(LMEM_FIXED, (strlen(lpszReturnName)+1));
  2075. //Copy the DisplayName for use later
  2076. strcpy(lpEntries[Entry].lpDisplayName, lpszReturnName);
  2077. //Allocate space for the EID (lpb)
  2078. lpEntries[Entry].lpb = (LPBYTE)LocalAlloc(LMEM_FIXED, lpSPropValueEntryID->Value.bin.cb);
  2079. //Copy the EID for use later
  2080. lpEntries[Entry].cb = lpSPropValueEntryID->Value.bin.cb;
  2081. memcpy(lpEntries[Entry].lpb,lpSPropValueEntryID->Value.bin.lpb,
  2082. lpEntries[Entry].cb);
  2083. //Free the SPropValue for use in the next loop
  2084. if (lpPropValue) {
  2085. for (unsigned int Prop = 0; Prop < cValues2; Prop++) {
  2086. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_STRING8) {
  2087. if (lpPropValue[Prop].Value.LPSZ) {
  2088. LocalFree(lpPropValue[Prop].Value.LPSZ);
  2089. lpPropValue[Prop].Value.LPSZ = NULL;
  2090. }
  2091. }
  2092. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_BINARY) {
  2093. if (lpPropValue[Prop].Value.bin.lpb) {
  2094. LocalFree(lpPropValue[Prop].Value.bin.lpb);
  2095. lpPropValue[Prop].Value.bin.lpb = NULL;
  2096. }
  2097. }
  2098. }
  2099. LocalFree(lpPropValue);
  2100. lpPropValue=NULL;
  2101. }
  2102. if (lpSPropValueEntryID) {
  2103. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  2104. lpSPropValueEntryID = NULL;
  2105. }
  2106. lpMailUser->Release();
  2107. lpMailUser = NULL;
  2108. }
  2109. //
  2110. // Create the Distribution Lists in the container
  2111. //
  2112. NumDLs = GetPrivateProfileInt("NamedPropsTestSuite","NumDLs",0,INIFILENAME);
  2113. lpDLs = (EntryID*)LocalAlloc(LMEM_FIXED, NumDLs * sizeof(EntryID));
  2114. LUIOut(L2, "Creating Distribution Lists");
  2115. for (DL = 0; DL < NumDLs; DL++) {
  2116. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  2117. IN 0, //Flags
  2118. OUT &cValues,
  2119. OUT &lpSPropValueDL);
  2120. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  2121. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  2122. retval=FALSE;
  2123. goto out;
  2124. }
  2125. // The returned value of PR_DEF_CREATE_DL is an
  2126. // EntryID which can be passed to CreateEntry
  2127. //
  2128. //LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  2129. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  2130. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  2131. IN 0,
  2132. OUT (LPMAPIPROP *) &lpDL);
  2133. if (HR_FAILED(hr)) {
  2134. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  2135. retval=FALSE;
  2136. goto out;
  2137. }
  2138. // Call QueryInterface on the object
  2139. hr = (lpDL->QueryInterface((REFIID)(IID_IDistList), (VOID **) &lpDL2));
  2140. if (HR_FAILED(hr)) {
  2141. LUIOut(L4, "QueryInterface on IID_IDistList FAILED. hr = 0x%x", hr);
  2142. retval = FALSE;
  2143. goto out;
  2144. }
  2145. else LUIOut(L4, "QueryInterface on IID_IDistList PASSED");
  2146. lstrcpy(szDLTag,"DistList1");
  2147. GetPrivateProfileString("NamedPropsTestSuite",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  2148. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  2149. //StrLen2 = (StrLen1 + sprintf((char*)&EntProp[0][StrLen1], " [Thread #%i] - ", *(int *)lpThreadNum));
  2150. _itoa(DL,(char*)&EntryBuf[strlen(EntryBuf)],10);
  2151. LUIOut(L3,"DistList Entry to Add: %s",EntryBuf);
  2152. cValues = 1;
  2153. PropValue[0].Value.LPSZ = (LPTSTR)EntryBuf;
  2154. hr = lpDL->SetProps(IN cValues,
  2155. IN PropValue,
  2156. IN NULL);
  2157. if (HR_FAILED(hr)) {
  2158. LUIOut(L3,"DL->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  2159. retval=FALSE;
  2160. goto out;
  2161. }
  2162. hr = lpDL->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  2163. if (HR_FAILED(hr)) {
  2164. LUIOut(L3,"DL->SaveChanges FAILED");
  2165. retval=FALSE;
  2166. goto out;
  2167. }
  2168. // Want a container interface to the DL, and since QueryInterface on a DL
  2169. // is currently broken (returns a MailUser interface when called with IID_IDistList)
  2170. // we do it the hard way. Call GetProps to get the EID for the new DL, and then
  2171. // call OpenEntry from the container or AB interfaces to open a DL interface
  2172. hr = lpDL->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  2173. IN 0, //Flags
  2174. OUT &cValues,
  2175. OUT &lpSPropValueEntryID);
  2176. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  2177. LUIOut(L3,"GetProps FAILED for MailUser");
  2178. retval=FALSE;
  2179. goto out;
  2180. }
  2181. lpDL2->Release(); //Free up this pointer so we can recycle it
  2182. hr = lpABCont->OpenEntry(IN lpSPropValueEntryID->Value.bin.cb,
  2183. IN (LPENTRYID) lpSPropValueEntryID->Value.bin.lpb,
  2184. IN &IID_IDistList,
  2185. IN MAPI_BEST_ACCESS,
  2186. OUT &ulObjType,
  2187. OUT (LPUNKNOWN*) &lpDL2);
  2188. if (HR_FAILED(hr)) {
  2189. LUIOut(L3,"OpenEntry failed for DistList");
  2190. retval=FALSE;
  2191. goto out;
  2192. }
  2193. LUIOut(L3, "Adding MailUser Members to the Distribution List");
  2194. //
  2195. // Now add mailuser entries to the DL
  2196. //
  2197. for (Entry = 0; Entry < NumEntries; Entry++) {
  2198. hr = lpDL2->CreateEntry( IN lpEntries[Entry].cb,
  2199. IN (LPENTRYID) lpEntries[Entry].lpb,
  2200. IN 0,
  2201. OUT (LPMAPIPROP *) &lpMailUser);
  2202. if (HR_FAILED(hr)) {
  2203. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  2204. retval=FALSE;
  2205. goto out;
  2206. }
  2207. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  2208. if (HR_FAILED(hr)) {
  2209. LUIOut(L3,"MailUser->SaveChanges FAILED");
  2210. retval=FALSE;
  2211. goto out;
  2212. }
  2213. lpMailUser->Release();
  2214. lpMailUser = NULL;
  2215. }
  2216. //Allocate space for the display name
  2217. lpDLs[DL].lpDisplayName = (char*)LocalAlloc(LMEM_FIXED, (strlen(EntryBuf)+1));
  2218. //Copy the DisplayName for use later
  2219. strcpy(lpDLs[DL].lpDisplayName, EntryBuf);
  2220. //Allocate space for the EID (lpb)
  2221. lpDLs[DL].lpb = (LPBYTE)LocalAlloc(LMEM_FIXED, lpSPropValueEntryID->Value.bin.cb);
  2222. //Copy the EID for use later
  2223. lpDLs[DL].cb = lpSPropValueEntryID->Value.bin.cb;
  2224. memcpy(lpDLs[DL].lpb,lpSPropValueEntryID->Value.bin.lpb,
  2225. lpDLs[DL].cb);
  2226. if (lpSPropValueEntryID) {
  2227. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  2228. lpSPropValueEntryID = NULL;
  2229. }
  2230. if (lpSPropValueDL) {
  2231. lpWABObject->FreeBuffer(lpSPropValueDL);
  2232. lpSPropValueDL = NULL;
  2233. }
  2234. lpDL->Release();
  2235. lpDL = NULL;
  2236. lpDL2->Release();
  2237. lpDL2 = NULL;
  2238. }
  2239. //
  2240. // Verify all entries are in the DL
  2241. //
  2242. LUIOut(L2, "Verifying MailUser Members are in the Distribution List");
  2243. for (DL = 0; DL < NumDLs; DL++) {
  2244. // Need to get an interface to the DL
  2245. hr = lpABCont->OpenEntry(IN lpDLs[DL].cb,
  2246. IN (LPENTRYID) lpDLs[DL].lpb,
  2247. IN &IID_IDistList,
  2248. IN MAPI_BEST_ACCESS,
  2249. OUT &ulObjType,
  2250. OUT (LPUNKNOWN*) &lpDL);
  2251. if (HR_FAILED(hr)) {
  2252. LUIOut(L3,"OpenEntry failed for DistList");
  2253. retval=FALSE;
  2254. goto out;
  2255. }
  2256. // Create a contents table to verify each added entry exists in the DL
  2257. hr = lpDL->GetContentsTable(ULONG(0), &lpTable);
  2258. if (HR_FAILED(hr)) {
  2259. LUIOut(L3,"DistList->GetContentsTable call FAILED, returned 0x%x", hr);
  2260. retval=FALSE;
  2261. goto out;
  2262. }
  2263. // Allocate the SpropValue ptr in the restriction structure
  2264. lpWABObject->AllocateBuffer(sizeof(SPropValue), (void**)&(Restriction.res.resProperty.lpProp));
  2265. Restriction.res.resProperty.lpProp = (SPropValue*)Restriction.res.resProperty.lpProp;
  2266. for (Entry = 0; Entry < NumEntries; Entry++) {
  2267. hr = lpDL->OpenEntry( IN lpEntries[Entry].cb,
  2268. IN (LPENTRYID) lpEntries[Entry].lpb,
  2269. IN &IID_IMailUser,
  2270. IN MAPI_BEST_ACCESS,
  2271. OUT &ulObjType,
  2272. OUT (LPUNKNOWN*) &lpMailUser);
  2273. if (HR_FAILED(hr)) {
  2274. LUIOut(L3,"OpenEntry failed for DistList");
  2275. retval=FALSE;
  2276. goto out;
  2277. }
  2278. lpMailUser->Release();
  2279. lpMailUser = NULL;
  2280. // Build the restriction structure to pass to lpTable->Restrict
  2281. //** For testing the fail case only, stub out for real testing
  2282. // lstrcpy(lpszDisplayNames[Counter2], "This should not match");
  2283. //**
  2284. Restriction.rt = RES_PROPERTY; //Property restriction
  2285. Restriction.res.resProperty.relop = RELOP_EQ; //Equals
  2286. Restriction.res.resProperty.ulPropTag = PR_DISPLAY_NAME;
  2287. Restriction.res.resProperty.lpProp->ulPropTag = PR_DISPLAY_NAME;
  2288. Restriction.res.resProperty.lpProp->Value.LPSZ = lpEntries[Entry].lpDisplayName;
  2289. hr = lpTable->Restrict(&Restriction, ULONG(0));
  2290. if (HR_FAILED(hr)) {
  2291. LUIOut(L3,"Table->Restrict call FAILED, returned 0x%x", hr);
  2292. retval=FALSE;
  2293. goto out;
  2294. }
  2295. hr = lpTable->QueryRows(LONG(1),
  2296. ULONG(0),
  2297. &lpRows);
  2298. if (HR_FAILED(hr)) {
  2299. LUIOut(L3,"Table->QueryRows call FAILED: Entry #%i, returned 0x%x", Entry, hr);
  2300. retval=FALSE;
  2301. goto out;
  2302. }
  2303. if (!lpRows->cRows) {
  2304. LUIOut(L2, "QueryRows did not find entry #%i. Test FAILED", Entry);
  2305. retval=FALSE;
  2306. goto out;
  2307. }
  2308. //** For testing purposes only, stub out for real testing
  2309. //InitializeCriticalSection(&CriticalSection);
  2310. //EnterCriticalSection(&CriticalSection);
  2311. //DisplayRows(lpRows);
  2312. //LeaveCriticalSection(&CriticalSection);
  2313. //**
  2314. // Does the user want us to cleanup after ourself?
  2315. Cleanup = GetPrivateProfileInt("NamedPropsTestSuite","Cleanup",1,INIFILENAME);
  2316. if (Cleanup) {
  2317. // Change the EntryID to a LPENTRYLIST
  2318. FindPropinRow(&lpRows->aRow[0],
  2319. PR_ENTRYID,
  2320. &PropIndex);
  2321. hr = HrCreateEntryListFromID(lpWABObject,
  2322. IN lpRows->aRow[0].lpProps[PropIndex].Value.bin.cb,
  2323. IN (ENTRYID*)lpRows->aRow[0].lpProps[PropIndex].Value.bin.lpb,
  2324. OUT &lpEntryList);
  2325. if (HR_FAILED(hr)) {
  2326. LUIOut(L3,"Could not Create Entry List");
  2327. retval=FALSE;
  2328. goto out;
  2329. }
  2330. // Then pass the lpEntryList to DeleteEntries to delete ...
  2331. hr = lpDL->DeleteEntries(IN lpEntryList,IN 0);
  2332. if (HR_FAILED(hr)) {
  2333. LUIOut(L3,"Could not Delete Entry %i. DeleteEntry returned 0x%x", Entry, hr);
  2334. FreeEntryList(lpWABObject, &lpEntryList);
  2335. retval=FALSE;
  2336. goto out;
  2337. }
  2338. FreeRows(lpWABObject, &lpRows); // Cleanup from first call to queryrows
  2339. // Verify the entry was deleted by calling QueryRows again
  2340. hr = lpTable->QueryRows(LONG(1),
  2341. ULONG(0),
  2342. &lpRows);
  2343. if (HR_FAILED(hr)) {
  2344. LUIOut(L3,"Table->QueryRows call FAILED: Entry #%i, returned 0x%x", Entry, hr);
  2345. retval=FALSE;
  2346. goto out;
  2347. }
  2348. if (lpRows->cRows) { // Should be 0 if deleted
  2349. LUIOut(L2, "QueryRows found entry #%i even tho it was deleted. Test FAILED", Entry);
  2350. retval=FALSE;
  2351. goto out;
  2352. }
  2353. }
  2354. //Cleanup
  2355. FreeRows(lpWABObject, &lpRows); // Cleanup from second call to queryrows
  2356. if (lpEntryList) {
  2357. FreeEntryList(lpWABObject, &lpEntryList);
  2358. lpEntryList = NULL;
  2359. }
  2360. }
  2361. LUIOut(L3, "All members verified for Distribution List #%i", DL);
  2362. //Free up memory
  2363. lpWABObject->FreeBuffer(Restriction.res.resProperty.lpProp);
  2364. if (lpTable) {
  2365. lpTable->Release();
  2366. lpTable = NULL;
  2367. }
  2368. lpDL->Release();
  2369. lpDL = NULL;
  2370. }
  2371. //
  2372. // Cleanup the WAB
  2373. //
  2374. if (Cleanup) {
  2375. LUIOut(L2, "Cleanup: Removing MailUsers");
  2376. // First, delete the MailUser entries from the wab
  2377. for (Entry = 0; Entry < NumEntries; Entry++) {
  2378. hr = HrCreateEntryListFromID(lpWABObject,
  2379. IN lpEntries[Entry].cb,
  2380. IN (ENTRYID*)lpEntries[Entry].lpb,
  2381. OUT &lpEntryList);
  2382. if (HR_FAILED(hr)) {
  2383. LUIOut(L3,"Could not Create Entry List");
  2384. retval=FALSE;
  2385. goto out;
  2386. }
  2387. // Then pass the lpEntryList to DeleteEntries to delete ...
  2388. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  2389. if (HR_FAILED(hr)) {
  2390. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  2391. FreeEntryList(lpWABObject, &lpEntryList);
  2392. retval=FALSE;
  2393. goto out;
  2394. }
  2395. LocalFree((HLOCAL)lpEntries[Entry].lpDisplayName);
  2396. LocalFree((HLOCAL)lpEntries[Entry].lpb);
  2397. FreeEntryList(lpWABObject, &lpEntryList);
  2398. }
  2399. LocalFree((HLOCAL)lpEntries);
  2400. LUIOut(L2, "Cleanup: Removing Distribution Lists");
  2401. // Now, delete the Distribution Lists from the wab
  2402. for (DL = 0; DL < NumDLs; DL++) {
  2403. hr = HrCreateEntryListFromID(lpWABObject,
  2404. IN lpDLs[DL].cb,
  2405. IN (ENTRYID*)lpDLs[DL].lpb,
  2406. OUT &lpEntryList);
  2407. if (HR_FAILED(hr)) {
  2408. LUIOut(L3,"Could not Create Entry List");
  2409. retval=FALSE;
  2410. goto out;
  2411. }
  2412. // Then pass the lpEntryList to DeleteEntries to delete ...
  2413. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  2414. if (HR_FAILED(hr)) {
  2415. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  2416. FreeEntryList(lpWABObject, &lpEntryList);
  2417. retval=FALSE;
  2418. goto out;
  2419. }
  2420. LocalFree((HLOCAL)lpDLs[DL].lpDisplayName);
  2421. LocalFree((HLOCAL)lpDLs[DL].lpb);
  2422. FreeEntryList(lpWABObject, &lpEntryList);
  2423. }
  2424. LocalFree((HLOCAL)lpDLs);
  2425. }
  2426. else {
  2427. LUIOut(L2, "Cleanup: User has requested that the MailUser entries and DistLists not be removed");
  2428. for (Entry = 0; Entry < NumEntries; Entry++) {
  2429. LocalFree((HLOCAL)lpEntries[Entry].lpDisplayName);
  2430. LocalFree((HLOCAL)lpEntries[Entry].lpb);
  2431. }
  2432. LocalFree((HLOCAL)lpEntries);
  2433. for (DL = 0; DL < NumDLs; DL++) {
  2434. LocalFree((HLOCAL)lpDLs[DL].lpDisplayName);
  2435. LocalFree((HLOCAL)lpDLs[DL].lpb);
  2436. }
  2437. LocalFree((HLOCAL)lpDLs);
  2438. }
  2439. out:
  2440. #ifdef PAB
  2441. if (lpEidPAB)
  2442. MAPIFreeBuffer(lpEidPAB);
  2443. if (lpSPropValueAddress)
  2444. MAPIFreeBuffer(lpSPropValueAddress);
  2445. if (lpSPropValueEntryID)
  2446. MAPIFreeBuffer(lpSPropValueEntryID);
  2447. if (lpSPropValueDL)
  2448. MAPIFreeBuffer(lpSPropValueDL);
  2449. #endif
  2450. #ifdef WAB
  2451. if (lpEidPAB)
  2452. lpWABObject->FreeBuffer(lpEidPAB);
  2453. if (lpSPropValueAddress)
  2454. lpWABObject->FreeBuffer(lpSPropValueAddress);
  2455. if (lpSPropValueEntryID)
  2456. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  2457. if (lpSPropValueDL)
  2458. lpWABObject->FreeBuffer(lpSPropValueDL);
  2459. #endif
  2460. //if (lpszDisplayName) LocalFree(lpszDisplayName);
  2461. if (lpMailUser)
  2462. lpMailUser->Release();
  2463. if (lpDL)
  2464. lpDL->Release();
  2465. if (lpDL2)
  2466. lpDL2->Release();
  2467. if (lpTable)
  2468. lpTable->Release();
  2469. if (lpABCont)
  2470. lpABCont->Release();
  2471. if (lpAdrBook)
  2472. lpAdrBook->Release();
  2473. #ifdef PAB
  2474. if (lpMAPISession)
  2475. lpMAPISession->Release();
  2476. MAPIUninitialize();
  2477. #endif
  2478. #ifdef WAB
  2479. if (lpWABObject)
  2480. lpWABObject->Release();
  2481. #endif
  2482. return retval;
  2483. }
  2484. BOOL PAB_IMailUserSetGetProps()
  2485. {
  2486. //DWORD nCells, counter;
  2487. ULONG ulFlags = 0;
  2488. HRESULT hr = hrSuccess;
  2489. SCODE sc = SUCCESS_SUCCESS;
  2490. int retval=TRUE;
  2491. LPADRBOOK lpAdrBook = NULL;
  2492. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  2493. LPABCONT lpPABCont= NULL,lpPABCont2= NULL;
  2494. LPABCONT lpDLCont= NULL;
  2495. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  2496. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  2497. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  2498. ULONG cbEid=0; // entry id of the entry being added
  2499. LPENTRYID lpEid=NULL;
  2500. char EntProp[10][BIG_BUF]; //MAX_PROP
  2501. ULONG cValues = 0, cValues2 = 0, ulObjType=NULL;
  2502. int i=0,k=0;
  2503. char EntryBuf[MAX_BUF];
  2504. char szDLTag[SML_BUF];
  2505. LPMAILUSER lpMailUser=NULL,lpMailUser2=NULL,lpDistList=NULL,lpDistList2=NULL;
  2506. LPMAPITABLE lpContentsTable = NULL;
  2507. LPSRowSet lpRowSet = NULL;
  2508. SPropValue PropValue[3] = {0}; // This value is 3 because we
  2509. // will be setting 3 properties:
  2510. // EmailAddress, DisplayName and
  2511. // AddressType.
  2512. SizedSPropTagArray(2, Cols) = { 2, {PR_OBJECT_TYPE, PR_ENTRYID } };
  2513. LPSPropValue lpSPropValueAddress = NULL;
  2514. LPSPropValue lpSPropValueMailUser = NULL;
  2515. LPSPropValue lpSPropValueDistList = NULL;
  2516. LPSPropValue lpSPropValueEntryID = NULL;
  2517. LPSPropValue lpSPropValueDL = NULL;
  2518. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  2519. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  2520. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  2521. SizedSPropTagArray(1,SPTArrayDisplayName) = {1, {PR_DISPLAY_NAME} };
  2522. LUIOut(L1," ");
  2523. LUIOut(L1,"Running PAB_IMailUserSetGetProps");
  2524. LUIOut(L2,"-> Verifies IMailUser->SetProps and GetProps are functional by performing the following:");
  2525. LUIOut(L2, " Attempts to Set/GetProps on a MailUser PR_DISPLAY_NAME using address1 from the");
  2526. LUIOut(L2, " ini file and checks...");
  2527. LUIOut(L2, " # The return code from both SetProps and GetProps");
  2528. LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  2529. LUIOut(L2, " Attempts to Set/GetProps on a DistList PR_DISPLAY_NAME using Name1 from the");
  2530. LUIOut(L2, " ini file and checks...");
  2531. LUIOut(L2, " # The return code from both SetProps and GetProps");
  2532. LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  2533. LUIOut(L1," ");
  2534. if (!GetAB(OUT &lpAdrBook)) {
  2535. retval = FALSE;
  2536. goto out;
  2537. }
  2538. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  2539. assert(lpAdrBook != NULL);
  2540. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  2541. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  2542. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  2543. if (HR_FAILED(hr)) {
  2544. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  2545. retval=FALSE;
  2546. goto out;
  2547. }
  2548. //
  2549. // Try to create a MailUser entry in the container
  2550. //
  2551. LUIOut(L2, "Creating a Mail User in the container");
  2552. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  2553. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  2554. assert(lpABCont != NULL);
  2555. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  2556. IN 0, //Flags
  2557. OUT &cValues,
  2558. OUT &lpSPropValueAddress);
  2559. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  2560. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  2561. retval=FALSE;
  2562. goto out;
  2563. }
  2564. // The returned value of PR_DEF_CREATE_MAILUSER is an
  2565. // EntryID which can be passed to CreateEntry
  2566. //
  2567. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  2568. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  2569. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  2570. IN 0,
  2571. OUT (LPMAPIPROP *) &lpMailUser);
  2572. if (HR_FAILED(hr)) {
  2573. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  2574. retval=FALSE;
  2575. goto out;
  2576. }
  2577. //
  2578. // Then set the properties
  2579. //
  2580. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  2581. cValues = 1; //# of props we are setting
  2582. lstrcpy(szDLTag,"Address1");
  2583. GetPrivateProfileString("CreateEntries",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  2584. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  2585. LUIOut(L2,"MailUser Entry to Add: %s",EntProp[0]);
  2586. for (i=0; i<(int)cValues;i++)
  2587. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  2588. hr = lpMailUser->SetProps(IN cValues,
  2589. IN PropValue,
  2590. IN NULL);
  2591. if (HR_FAILED(hr)) {
  2592. LUIOut(L3,"MailUser->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  2593. retval=FALSE;
  2594. goto out;
  2595. }
  2596. else LUIOut(L3,"MailUser->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  2597. LUIOut(L2, "Calling MailUser->GetProps to verify the properties are what we expect");
  2598. hr = lpMailUser->GetProps( IN (LPSPropTagArray) &SPTArrayDisplayName,
  2599. IN 0,
  2600. OUT &cValues2,
  2601. OUT (LPSPropValue FAR *)&lpSPropValueMailUser);
  2602. if ((HR_FAILED(hr))||(PropError(lpSPropValueMailUser->ulPropTag, cValues2))) {
  2603. LUIOut(L3,"MailUser->GetProps call FAILED");
  2604. retval=FALSE;
  2605. goto out;
  2606. }
  2607. else LUIOut(L3,"MailUser->GetProps call PASSED. Now verifying property array...");
  2608. for (i=0; i<(int)cValues;i++) {
  2609. if (lstrcmp(PropValue[i].Value.LPSZ, lpSPropValueMailUser->Value.LPSZ)) { //FAILED
  2610. LUIOut(L3, "Display names are not egual. [%s != %s]",
  2611. PropValue[i].Value.LPSZ, lpSPropValueMailUser->Value.LPSZ);
  2612. retval = FALSE;
  2613. goto out;
  2614. }
  2615. else LUIOut(L3, "Display names are equal. [%s = %s]",
  2616. PropValue[i].Value.LPSZ, lpSPropValueMailUser->Value.LPSZ);
  2617. }
  2618. LUIOut(L2, "MailUserSet/GetProps PASSED");
  2619. #ifdef DISTLIST
  2620. //
  2621. // Try to create a DL entry in the container
  2622. //
  2623. LUIOut(L2, "Creating a Distribution List in the container");
  2624. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_DL property");
  2625. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_DL
  2626. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  2627. IN 0, //Flags
  2628. OUT &cValues,
  2629. OUT &lpSPropValueDL);
  2630. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  2631. LUIOut(L3,"GetProps failed for Default DL template");
  2632. retval=FALSE;
  2633. goto out;
  2634. }
  2635. // The returned value of PR_DEF_CREATE_DL is an
  2636. // EntryID which one can pass to CreateEntry
  2637. //
  2638. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  2639. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  2640. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  2641. IN 0,
  2642. OUT (LPMAPIPROP *) &lpDistList);
  2643. if (HR_FAILED(hr)) {
  2644. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  2645. retval=FALSE;
  2646. goto out;
  2647. }
  2648. //
  2649. // Then set the properties
  2650. //
  2651. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  2652. cValues = 1; //# of props we are setting
  2653. lstrcpy(szDLTag,"Name1");
  2654. GetPrivateProfileString("CreatePDL",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  2655. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  2656. LUIOut(L2,"DistList Entry to Add: %s",EntProp[0]);
  2657. for (i=0; i<(int)cValues;i++)
  2658. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  2659. hr = lpDistList->SetProps(IN cValues,
  2660. IN PropValue,
  2661. IN NULL);
  2662. if (HR_FAILED(hr)) {
  2663. LUIOut(L3,"DistList->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  2664. retval=FALSE;
  2665. goto out;
  2666. }
  2667. else LUIOut(L3,"DistList->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  2668. LUIOut(L2, "Calling DistList->GetProps to verify the properties are what we expect");
  2669. hr = lpDistList->GetProps( IN (LPSPropTagArray) &SPTArrayDisplayName,
  2670. IN 0,
  2671. OUT &cValues2,
  2672. OUT (LPSPropValue FAR *)&lpSPropValueDistList);
  2673. if ((HR_FAILED(hr))||(PropError(lpSPropValueDistList->ulPropTag))) {
  2674. LUIOut(L3,"DistList->GetProps call FAILED");
  2675. retval=FALSE;
  2676. goto out;
  2677. }
  2678. else LUIOut(L3,"DistList->GetProps call PASSED. Now verifying property array...");
  2679. for (i=0; i<(int)cValues;i++) {
  2680. if (lstrcmp(PropValue[i].Value.LPSZ, lpSPropValueDistList->Value.LPSZ)) { //FAILED
  2681. LUIOut(L3, "Display names are not egual. [%s != %s]",
  2682. PropValue[i].Value.LPSZ, lpSPropValueDistList->Value.LPSZ);
  2683. retval = FALSE;
  2684. goto out;
  2685. }
  2686. else LUIOut(L3, "Display names are equal. [%s = %s]",
  2687. PropValue[i].Value.LPSZ, lpSPropValueDistList->Value.LPSZ);
  2688. }
  2689. LUIOut(L2, "DistList Set/GetProps PASSED");
  2690. #endif DISTLIST
  2691. out:
  2692. #ifdef PAB
  2693. if (lpEid)
  2694. MAPIFreeBuffer(lpEid);
  2695. if (lpEidPAB)
  2696. MAPIFreeBuffer(lpEidPAB);
  2697. if (lpSPropValueAddress)
  2698. MAPIFreeBuffer(lpSPropValueAddress);
  2699. if (lpSPropValueMailUser)
  2700. MAPIFreeBuffer(lpSPropValueMailUser);
  2701. if (lpSPropValueEntryID)
  2702. MAPIFreeBuffer(lpSPropValueEntryID);
  2703. if (lpSPropValueDL)
  2704. MAPIFreeBuffer(lpSPropValueDL);
  2705. #endif
  2706. #ifdef WAB
  2707. if (lpEid)
  2708. lpWABObject->FreeBuffer(lpEid);
  2709. if (lpEidPAB)
  2710. lpWABObject->FreeBuffer(lpEidPAB);
  2711. if (lpSPropValueAddress)
  2712. lpWABObject->FreeBuffer(lpSPropValueAddress);
  2713. if (lpSPropValueMailUser)
  2714. lpWABObject->FreeBuffer(lpSPropValueMailUser);
  2715. if (lpSPropValueEntryID)
  2716. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  2717. if (lpSPropValueDL)
  2718. lpWABObject->FreeBuffer(lpSPropValueDL);
  2719. #endif
  2720. if (lpMailUser)
  2721. lpMailUser->Release();
  2722. if (lpMailUser2)
  2723. lpMailUser2->Release();
  2724. if (lpDistList)
  2725. lpDistList->Release();
  2726. if (lpDistList2)
  2727. lpDistList2->Release();
  2728. if (lpContentsTable)
  2729. lpContentsTable->Release();
  2730. if (lpPABCont)
  2731. lpPABCont->Release();
  2732. if (lpABCont)
  2733. lpABCont->Release();
  2734. if (lpDLCont)
  2735. lpDLCont->Release();
  2736. if (lpAdrBook)
  2737. lpAdrBook->Release();
  2738. #ifdef PAB
  2739. if (lpMAPISession)
  2740. lpMAPISession->Release();
  2741. MAPIUninitialize();
  2742. #endif
  2743. #ifdef WAB
  2744. if (lpWABObject)
  2745. lpWABObject->Release();
  2746. #endif
  2747. return retval;
  2748. }
  2749. BOOL PAB_IMailUserSaveChanges()
  2750. {
  2751. //DWORD nCells, counter;
  2752. ULONG ulFlags = 0;
  2753. HRESULT hr = hrSuccess;
  2754. SCODE sc = SUCCESS_SUCCESS;
  2755. int retval=TRUE;
  2756. LPADRBOOK lpAdrBook = NULL;
  2757. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  2758. LPABCONT lpPABCont= NULL,lpPABCont2= NULL;
  2759. LPABCONT lpDLCont= NULL;
  2760. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  2761. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  2762. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  2763. ULONG cbEid=0; // entry id of the entry being added
  2764. LPENTRYID lpEid=NULL;
  2765. ULONG cValues = 0, cValues2 = 0, ulObjType=NULL;
  2766. ULONG cRows = 0;
  2767. ULONG iEntry = 0;
  2768. int i=0,k=0;
  2769. LPMAILUSER lpMailUser=NULL,lpMailUser2=NULL,lpDistList=NULL,lpDistList2=NULL;
  2770. SPropValue* lpPropValue = NULL;
  2771. SizedSPropTagArray(2, Cols) = { 2, {PR_OBJECT_TYPE, PR_ENTRYID } };
  2772. LPSPropValue lpSPropValueAddress = NULL;
  2773. LPSPropValue lpSPropValueMailUser = NULL;
  2774. LPSPropValue lpSPropValueDistList = NULL;
  2775. LPSPropValue lpSPropValueEntryID = NULL;
  2776. LPSPropValue lpSPropValueDL = NULL;
  2777. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  2778. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  2779. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  2780. SizedSPropTagArray(1,SPTArrayDisplayName) = {1, {PR_DISPLAY_NAME} };
  2781. LUIOut(L1," ");
  2782. LUIOut(L1,"Running PAB_IMailUserSaveChanges");
  2783. LUIOut(L2,"-> Verifies IMailUser->SaveChanges is functional by performing the following:");
  2784. LUIOut(L2, " Calls SetProps followed by SaveChanges on a MailUser PR_DISPLAY_NAME using address1 from the");
  2785. LUIOut(L2, " ini file and checks...");
  2786. LUIOut(L2, " # The return code from SaveChanges");
  2787. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  2788. LUIOut(L2, " Calls SetProps followed by SaveChanges on a DistList PR_DISPLAY_NAME using address1 from the");
  2789. LUIOut(L2, " ini file and checks...");
  2790. LUIOut(L2, " # The return code from SaveChanges");
  2791. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  2792. LUIOut(L1," ");
  2793. if (!GetAB(OUT &lpAdrBook)) {
  2794. retval = FALSE;
  2795. goto out;
  2796. }
  2797. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  2798. assert(lpAdrBook != NULL);
  2799. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  2800. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  2801. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  2802. if (HR_FAILED(hr)) {
  2803. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  2804. retval=FALSE;
  2805. goto out;
  2806. }
  2807. //
  2808. // Try to create a MailUser entry in the container
  2809. //
  2810. LUIOut(L2, "Creating a Mail User in the container");
  2811. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  2812. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  2813. assert(lpABCont != NULL);
  2814. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  2815. IN 0, //Flags
  2816. OUT &cValues,
  2817. OUT &lpSPropValueAddress);
  2818. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  2819. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  2820. retval=FALSE;
  2821. goto out;
  2822. }
  2823. // The returned value of PR_DEF_CREATE_MAILUSER is an
  2824. // EntryID which can be passed to CreateEntry
  2825. //
  2826. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  2827. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  2828. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  2829. IN 0,
  2830. OUT (LPMAPIPROP *) &lpMailUser);
  2831. if (HR_FAILED(hr)) {
  2832. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  2833. retval=FALSE;
  2834. goto out;
  2835. }
  2836. //
  2837. // Then set the properties
  2838. //
  2839. #ifdef TESTPASS
  2840. while (1) {
  2841. #endif
  2842. CreateProps(IN INIFILENAME, IN "Properties", OUT &lpPropValue, OUT &cValues2, IN AUTONUM_OFF, IN NULL, OUT NULL);
  2843. LUIOut(L4, "Creating a MailUser with %i properties.", cValues2);
  2844. hr = lpMailUser->SetProps(IN cValues2,
  2845. IN lpPropValue,
  2846. IN NULL);
  2847. if (HR_FAILED(hr)) {
  2848. LUIOut(L3,"MailUser->SetProps call FAILED");
  2849. retval=FALSE;
  2850. goto out;
  2851. }
  2852. else LUIOut(L3,"MailUser->SetProps call PASSED");
  2853. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  2854. if (HR_FAILED(hr)) {
  2855. LUIOut(L3,"MailUser->SaveChanges FAILED");
  2856. retval=FALSE;
  2857. goto out;
  2858. }
  2859. else LUIOut(L3,"MailUser->SaveChanges PASSED, entry added to PAB/WAB");
  2860. // Now retrieve all the props and compare to what we expect
  2861. hr = lpMailUser->GetProps( IN (LPSPropTagArray) NULL, //Want all props
  2862. IN 0, //Flags
  2863. OUT &cValues,
  2864. OUT &lpSPropValueEntryID);
  2865. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  2866. LUIOut(L3,"GetProps FAILED for MailUser");
  2867. retval=FALSE;
  2868. goto out;
  2869. }
  2870. DisplayProp(lpSPropValueEntryID, PR_GIVEN_NAME, cValues);
  2871. DisplayProp(lpSPropValueEntryID, PR_SURNAME, cValues);
  2872. if (!CompareProps(lpPropValue, cValues2, lpSPropValueEntryID, cValues)) {
  2873. retval=FALSE;
  2874. goto out;
  2875. }
  2876. else LUIOut(L4, "Compared expected and found props. No differences detected.");
  2877. // Free the memory associated with this ptr so the ptr can be reused below
  2878. if (lpSPropValueEntryID)
  2879. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  2880. if (lpPropValue) {
  2881. for (unsigned int Prop = 0; Prop < cValues2; Prop++) {
  2882. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_STRING8) {
  2883. if (lpPropValue[Prop].Value.LPSZ) {
  2884. LocalFree(lpPropValue[Prop].Value.LPSZ);
  2885. lpPropValue[Prop].Value.LPSZ = NULL;
  2886. }
  2887. }
  2888. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_BINARY) {
  2889. if (lpPropValue[Prop].Value.bin.lpb) {
  2890. LocalFree(lpPropValue[Prop].Value.bin.lpb);
  2891. lpPropValue[Prop].Value.bin.lpb = NULL;
  2892. }
  2893. }
  2894. }
  2895. LocalFree(lpPropValue);
  2896. lpPropValue=NULL;
  2897. }
  2898. #ifdef TESTPASS
  2899. }
  2900. #endif
  2901. // Now delete the entry from the wab
  2902. hr = lpMailUser->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  2903. IN 0, //Flags
  2904. OUT &cValues,
  2905. OUT &lpSPropValueEntryID);
  2906. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  2907. LUIOut(L3,"GetProps FAILED for MailUser");
  2908. retval=FALSE;
  2909. goto out;
  2910. }
  2911. hr = HrCreateEntryListFromID(lpWABObject,
  2912. IN lpSPropValueEntryID->Value.bin.cb,
  2913. IN (ENTRYID*)lpSPropValueEntryID->Value.bin.lpb,
  2914. OUT &lpEntryList);
  2915. if (HR_FAILED(hr)) {
  2916. LUIOut(L3,"Could not Create Entry List");
  2917. retval=FALSE;
  2918. goto out;
  2919. }
  2920. // Then pass the lpEntryList to DeleteEntries to delete ...
  2921. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  2922. if (HR_FAILED(hr)) {
  2923. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  2924. FreeEntryList(lpWABObject, &lpEntryList);
  2925. retval=FALSE;
  2926. goto out;
  2927. }
  2928. FreeEntryList(lpWABObject, &lpEntryList);
  2929. out:
  2930. #ifdef PAB
  2931. if (lpEid)
  2932. MAPIFreeBuffer(lpEid);
  2933. if (lpEidPAB)
  2934. MAPIFreeBuffer(lpEidPAB);
  2935. if (lpSPropValueAddress)
  2936. MAPIFreeBuffer(lpSPropValueAddress);
  2937. if (lpSPropValueEntryID)
  2938. MAPIFreeBuffer(lpSPropValueEntryID);
  2939. if (lpSPropValueDL)
  2940. MAPIFreeBuffer(lpSPropValueDL);
  2941. #endif
  2942. #ifdef WAB
  2943. if (lpEid)
  2944. lpWABObject->FreeBuffer(lpEid);
  2945. if (lpEidPAB)
  2946. lpWABObject->FreeBuffer(lpEidPAB);
  2947. if (lpSPropValueAddress)
  2948. lpWABObject->FreeBuffer(lpSPropValueAddress);
  2949. if (lpSPropValueEntryID)
  2950. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  2951. if (lpSPropValueDL)
  2952. lpWABObject->FreeBuffer(lpSPropValueDL);
  2953. #endif
  2954. if (lpPropValue) {
  2955. for (unsigned int Prop = 0; Prop < cValues2; Prop++) {
  2956. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_STRING8) {
  2957. if (lpPropValue[Prop].Value.LPSZ) {
  2958. LocalFree(lpPropValue[Prop].Value.LPSZ);
  2959. lpPropValue[Prop].Value.LPSZ = NULL;
  2960. }
  2961. }
  2962. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_BINARY) {
  2963. if (lpPropValue[Prop].Value.bin.lpb) {
  2964. LocalFree(lpPropValue[Prop].Value.bin.lpb);
  2965. lpPropValue[Prop].Value.bin.lpb = NULL;
  2966. }
  2967. }
  2968. }
  2969. LocalFree(lpPropValue);
  2970. lpPropValue=NULL;
  2971. }
  2972. if (lpMailUser)
  2973. lpMailUser->Release();
  2974. if (lpMailUser2)
  2975. lpMailUser2->Release();
  2976. if (lpDistList)
  2977. lpDistList->Release();
  2978. if (lpDistList2)
  2979. lpDistList2->Release();
  2980. if (lpPABCont)
  2981. lpPABCont->Release();
  2982. if (lpABCont)
  2983. lpABCont->Release();
  2984. if (lpDLCont)
  2985. lpDLCont->Release();
  2986. if (lpAdrBook)
  2987. lpAdrBook->Release();
  2988. #ifdef PAB
  2989. if (lpMAPISession)
  2990. lpMAPISession->Release();
  2991. MAPIUninitialize();
  2992. #endif
  2993. #ifdef WAB
  2994. if (lpWABObject)
  2995. lpWABObject->Release();
  2996. #endif
  2997. return retval;
  2998. }
  2999. BOOL PAB_IABContainerResolveNames()
  3000. {
  3001. //DWORD nCells, counter;
  3002. BOOL Found = FALSE;
  3003. ULONG ulFlags = 0;
  3004. HRESULT hr = hrSuccess;
  3005. SCODE sc = SUCCESS_SUCCESS;
  3006. int retval=TRUE;
  3007. int NumEntries, NumProps;
  3008. unsigned int i = 0, idx = 0, cMaxProps =0, cEntries = 0;
  3009. char lpszInput[] = "Resolve THIS buddy!01234567891123456789212345678931234567894123456789512345678961234567897123456789812345678991234567890123456789112345678921234567893123456789412345678951234567896123456789712345678981234567899123456789012345678911234567892123456789312345678941234567895123456789612345678971234567898123456789", lpszInput2[] = "Resolve THIS DL buddy!";
  3010. LPADRLIST lpAdrList = NULL;
  3011. ULONG rgFlagList[2];
  3012. LPFlagList lpFlagList = (LPFlagList)rgFlagList;
  3013. LPADRBOOK lpAdrBook = NULL;
  3014. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  3015. LPABCONT lpPABCont= NULL,lpPABCont2= NULL;
  3016. LPABCONT lpDLCont= NULL;
  3017. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  3018. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  3019. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  3020. ULONG cbEid=0; // entry id of the entry being added
  3021. LPENTRYID lpEid=NULL;
  3022. char EntProp[10][BIG_BUF]; //MAX_PROP
  3023. ULONG cValues = 0, cValues2 = 0, ulObjType=NULL;
  3024. ULONG cRows = 0;
  3025. ULONG iEntry = 0;
  3026. int k=0;
  3027. LPMAILUSER lpMailUser=NULL,lpMailUser2=NULL,lpDistList=NULL,lpDistList2=NULL;
  3028. SPropValue PropValue[3] = {0}; // This value is 3 because we
  3029. // will be setting 3 properties:
  3030. // EmailAddress, DisplayName and
  3031. // AddressType.
  3032. SizedSPropTagArray(2, SPTArrayCols) = { 2, {PR_DISPLAY_NAME, PR_ENTRYID } };
  3033. LPSPropValue lpSPropValueAddress = NULL;
  3034. LPSPropValue lpSPropValueMailUser = NULL;
  3035. LPSPropValue lpSPropValueDistList = NULL;
  3036. LPSPropValue lpSPropValueEntryID = NULL;
  3037. LPSPropValue lpSPropValueDL = NULL;
  3038. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  3039. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  3040. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  3041. SizedSPropTagArray(1,SPTArrayDisplayName) = {1, {PR_DISPLAY_NAME} };
  3042. LUIOut(L1," ");
  3043. LUIOut(L1,"Running PAB_IABContainerResolveNames");
  3044. LUIOut(L2,"-> Verifies IABContainer->ResolveNames is functional by performing the following:");
  3045. LUIOut(L2, " Calls SetProps followed by SaveChanges on a MailUser PR_DISPLAY_NAME using a test string, and checks...");
  3046. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  3047. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  3048. LUIOut(L2, " string to the original test string.");
  3049. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  3050. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  3051. LUIOut(L2, " Calls SetProps followed by SaveChanges on a DistList PR_DISPLAY_NAME using a test string, and checks...");
  3052. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  3053. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  3054. LUIOut(L2, " string to the original test string.");
  3055. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  3056. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  3057. LUIOut(L1," ");
  3058. if (!GetAB(OUT &lpAdrBook)) {
  3059. retval = FALSE;
  3060. goto out;
  3061. }
  3062. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  3063. assert(lpAdrBook != NULL);
  3064. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  3065. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  3066. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  3067. if (HR_FAILED(hr)) {
  3068. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  3069. retval=FALSE;
  3070. goto out;
  3071. }
  3072. //
  3073. // Try to create a MailUser entry in the container
  3074. //
  3075. LUIOut(L2, "Creating a Mail User in the container");
  3076. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  3077. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  3078. assert(lpABCont != NULL);
  3079. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  3080. IN 0, //Flags
  3081. OUT &cValues,
  3082. OUT &lpSPropValueAddress);
  3083. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  3084. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  3085. retval=FALSE;
  3086. goto out;
  3087. }
  3088. // The returned value of PR_DEF_CREATE_MAILUSER is an
  3089. // EntryID which can be passed to CreateEntry
  3090. //
  3091. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  3092. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  3093. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  3094. IN 0,
  3095. OUT (LPMAPIPROP *) &lpMailUser);
  3096. if (HR_FAILED(hr)) {
  3097. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  3098. retval=FALSE;
  3099. goto out;
  3100. }
  3101. //
  3102. // Then set the properties
  3103. //
  3104. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  3105. cValues = 1; //# of props we are setting
  3106. /* lstrcpy(szDLTag,"Address1");
  3107. GetPrivateProfileString("CreateEntries",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  3108. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  3109. */
  3110. lstrcpy((LPTSTR)EntProp[0], lpszInput);
  3111. LUIOut(L2,"MailUser Entry to Add: %s",EntProp[0]);
  3112. for (i=0; i<(int)cValues;i++)
  3113. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  3114. hr = lpMailUser->SetProps(IN cValues,
  3115. IN PropValue,
  3116. IN NULL);
  3117. if (HR_FAILED(hr)) {
  3118. LUIOut(L3,"MailUser->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  3119. retval=FALSE;
  3120. goto out;
  3121. }
  3122. else LUIOut(L3,"MailUser->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  3123. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  3124. if (HR_FAILED(hr)) {
  3125. LUIOut(L3,"MailUser->SaveChanges FAILED");
  3126. retval=FALSE;
  3127. goto out;
  3128. }
  3129. else LUIOut(L3,"MailUser->SaveChanges PASSED, entry added to PAB/WAB");
  3130. //
  3131. // Do a ResolveNames on the string
  3132. //
  3133. LUIOut(L2, "Retrieving the entry and verifying against what we tried to save.");
  3134. NumEntries = 1, NumProps = 1;
  3135. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  3136. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3137. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszInput;
  3138. lpFlagList->cFlags = 1;
  3139. lpFlagList->ulFlag[0] = MAPI_UNRESOLVED;
  3140. hr = lpABCont->ResolveNames(
  3141. (LPSPropTagArray)&SPTArrayCols, // tag set for disp_name and eid
  3142. 0, // ulFlags
  3143. lpAdrList,
  3144. lpFlagList);
  3145. if (HR_FAILED(hr)) {
  3146. LUIOut(L3,"ABContainer->ResolveNames call FAILED, returned 0x%x", hr);
  3147. retval=FALSE;
  3148. goto out;
  3149. }
  3150. else LUIOut(L3,"ABContainer->ResolveNames call PASSED");
  3151. VerifyResolvedAdrList(lpAdrList, lpszInput);
  3152. // Now delete the entry from the wab
  3153. hr = lpMailUser->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  3154. IN 0, //Flags
  3155. OUT &cValues,
  3156. OUT &lpSPropValueEntryID);
  3157. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  3158. LUIOut(L3,"GetProps FAILED for MailUser");
  3159. retval=FALSE;
  3160. goto out;
  3161. }
  3162. hr = HrCreateEntryListFromID(lpWABObject,
  3163. IN lpSPropValueEntryID->Value.bin.cb,
  3164. IN (ENTRYID*)lpSPropValueEntryID->Value.bin.lpb,
  3165. OUT &lpEntryList);
  3166. if (HR_FAILED(hr)) {
  3167. LUIOut(L3,"Could not Create Entry List");
  3168. retval=FALSE;
  3169. goto out;
  3170. }
  3171. // Then pass the lpEntryList to DeleteEntries to delete ...
  3172. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  3173. if (HR_FAILED(hr)) {
  3174. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  3175. FreeEntryList(lpWABObject, &lpEntryList);
  3176. retval=FALSE;
  3177. goto out;
  3178. }
  3179. FreeEntryList(lpWABObject, &lpEntryList);
  3180. FreeAdrList(lpWABObject, &lpAdrList); // Free lpAdrList and properties
  3181. #ifdef DISTLIST
  3182. //
  3183. // Try to create a DL entry in the container
  3184. //
  3185. LUIOut(L2, "Creating a Distribution List in the container");
  3186. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_DL property");
  3187. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_DL
  3188. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  3189. IN 0, //Flags
  3190. OUT &cValues,
  3191. OUT &lpSPropValueDL);
  3192. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  3193. LUIOut(L3,"GetProps failed for Default DL template");
  3194. retval=FALSE;
  3195. goto out;
  3196. }
  3197. // The returned value of PR_DEF_CREATE_DL is an
  3198. // EntryID which one can pass to CreateEntry
  3199. //
  3200. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  3201. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  3202. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  3203. IN 0,
  3204. OUT (LPMAPIPROP *) &lpDistList);
  3205. if (HR_FAILED(hr)) {
  3206. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  3207. retval=FALSE;
  3208. goto out;
  3209. }
  3210. //
  3211. // Then set the properties
  3212. //
  3213. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  3214. cValues = 1; //# of props we are setting
  3215. /* lstrcpy(szDLTag,"Name1");
  3216. GetPrivateProfileString("CreatePDL",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  3217. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  3218. */
  3219. lstrcpy((LPTSTR)EntProp[0], lpszInput2);
  3220. LUIOut(L2,"DistList Entry to Add: %s",EntProp[0]);
  3221. for (i=0; i<(int)cValues;i++)
  3222. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  3223. hr = lpDistList->SetProps(IN cValues,
  3224. IN PropValue,
  3225. IN NULL);
  3226. if (HR_FAILED(hr)) {
  3227. LUIOut(L3,"DistList->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  3228. retval=FALSE;
  3229. goto out;
  3230. }
  3231. else LUIOut(L3,"DistList->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  3232. hr = lpDistList->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  3233. if (HR_FAILED(hr)) {
  3234. LUIOut(L3,"DistList->SaveChanges FAILED");
  3235. retval=FALSE;
  3236. goto out;
  3237. }
  3238. else LUIOut(L3,"DistList->SaveChanges PASSED, entry added to PAB/WAB");
  3239. //
  3240. // Do a ResolveNames on the string
  3241. //
  3242. LUIOut(L2, "Retrieving the entry and verifying against what we tried to save.");
  3243. // use WAB Allocators here
  3244. #ifdef PAB
  3245. if (! (sc = MAPIAllocateBuffer(sizeof(ADRLIST) + sizeof(ADRENTRY), (void **)&lpAdrList))) {
  3246. #endif //PAB
  3247. #ifdef WAB
  3248. if (! (sc = lpWABObject->AllocateBuffer(sizeof(ADRLIST) + sizeof(ADRENTRY), (void **)&lpAdrList))) {
  3249. #endif //WAB
  3250. lpAdrList->cEntries = 1;
  3251. lpAdrList->aEntries[0].ulReserved1 = 0;
  3252. lpAdrList->aEntries[0].cValues = 1;
  3253. #ifdef PAB
  3254. if (! (sc = MAPIAllocateMore(sizeof(SPropValue), lpAdrList,
  3255. (void **)&lpAdrList->aEntries[0].rgPropVals))) {
  3256. #endif //WAB
  3257. #ifdef WAB
  3258. if (! (sc = lpWABObject->AllocateMore(sizeof(SPropValue), lpAdrList,
  3259. (void **)&lpAdrList->aEntries[0].rgPropVals))) {
  3260. #endif //WAB
  3261. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3262. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszInput2;
  3263. lpFlagList->cFlags = 1;
  3264. lpFlagList->ulFlag[0] = MAPI_UNRESOLVED;
  3265. hr = lpABCont->ResolveNames(
  3266. (LPSPropTagArray)&SPTArrayCols, // tag set for disp_name and eid
  3267. 0, // ulFlags
  3268. lpAdrList,
  3269. lpFlagList);
  3270. if (HR_FAILED(hr)) {
  3271. LUIOut(L3,"ABContainer->ResolveNames call FAILED, returned 0x%x", hr);
  3272. retval=FALSE;
  3273. goto out;
  3274. }
  3275. else LUIOut(L3,"ABContainer->ResolveNames call PASSED");
  3276. Found = FALSE;
  3277. // Search through returned AdrList for our entry
  3278. for(i=0; ((i<(int) lpAdrList->cEntries) && (!Found)); ++i) {
  3279. cMaxProps = (int)lpAdrList->aEntries[i].cValues;
  3280. //Check to see if Display Name exists
  3281. idx=0;
  3282. while((lpAdrList->aEntries[i].rgPropVals[idx].ulPropTag != PR_DISPLAY_NAME )
  3283. && retval) {
  3284. idx++;
  3285. if(idx == cMaxProps) {
  3286. LUIOut(L4, "PR_DISPLAY_NAME was not found in the lpAdrList");
  3287. retval = FALSE;
  3288. }
  3289. }
  3290. LUIOut(L4,"Display Name: %s",lpAdrList->aEntries[i].rgPropVals[idx].Value.LPSZ);
  3291. if (!lstrcmp(lpAdrList->aEntries[i].rgPropVals[idx].Value.LPSZ,lpszInput2)) {
  3292. LUIOut(L3, "Found the entry we just added");
  3293. Found = TRUE;
  3294. }
  3295. //Check to see if EntryID exists
  3296. LUIOut(L3, "Verifying a PR_ENTRYID entry exists in the PropertyTagArray");
  3297. idx=0;
  3298. while((lpAdrList->aEntries[i].rgPropVals[idx].ulPropTag != PR_ENTRYID )
  3299. && retval) {
  3300. idx++;
  3301. if(idx == cMaxProps) {
  3302. LUIOut(L4, "PR_ENTRYID was not found in the lpAdrList");
  3303. retval = FALSE;
  3304. }
  3305. }
  3306. if (!Found) LUIOut(L3, "Did not find the entry. Test FAILED");
  3307. if (idx < cMaxProps) LUIOut(L3, "EntryID found");
  3308. if (!(retval && Found)) retval = FALSE;
  3309. else {
  3310. // Store EID for call to OpenEntry
  3311. }
  3312. }
  3313. }
  3314. #ifdef PAB
  3315. MAPIFreeBuffer(lpAdrList);
  3316. #endif //PAB
  3317. #ifdef WAB
  3318. lpWABObject->FreeBuffer(lpAdrList);
  3319. #endif //WAB
  3320. }
  3321. #endif //DISTLIST
  3322. out:
  3323. // Free lpAdrList and properties
  3324. FreeAdrList(lpWABObject, &lpAdrList);
  3325. #ifdef PAB
  3326. if (lpEid)
  3327. MAPIFreeBuffer(lpEid);
  3328. if (lpEidPAB)
  3329. MAPIFreeBuffer(lpEidPAB);
  3330. if (lpSPropValueAddress)
  3331. MAPIFreeBuffer(lpSPropValueAddress);
  3332. if (lpSPropValueEntryID)
  3333. MAPIFreeBuffer(lpSPropValueEntryID);
  3334. if (lpSPropValueDL)
  3335. MAPIFreeBuffer(lpSPropValueDL);
  3336. #endif
  3337. #ifdef WAB
  3338. if (lpEid)
  3339. lpWABObject->FreeBuffer(lpEid);
  3340. if (lpEidPAB)
  3341. lpWABObject->FreeBuffer(lpEidPAB);
  3342. if (lpSPropValueAddress)
  3343. lpWABObject->FreeBuffer(lpSPropValueAddress);
  3344. if (lpSPropValueEntryID)
  3345. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  3346. if (lpSPropValueDL)
  3347. lpWABObject->FreeBuffer(lpSPropValueDL);
  3348. #endif
  3349. if (lpMailUser)
  3350. lpMailUser->Release();
  3351. if (lpMailUser2)
  3352. lpMailUser2->Release();
  3353. if (lpDistList)
  3354. lpDistList->Release();
  3355. if (lpDistList2)
  3356. lpDistList2->Release();
  3357. if (lpPABCont)
  3358. lpPABCont->Release();
  3359. if (lpABCont)
  3360. lpABCont->Release();
  3361. if (lpDLCont)
  3362. lpDLCont->Release();
  3363. if (lpAdrBook)
  3364. lpAdrBook->Release();
  3365. #ifdef PAB
  3366. if (lpMAPISession)
  3367. lpMAPISession->Release();
  3368. MAPIUninitialize();
  3369. #endif
  3370. #ifdef WAB
  3371. if (lpWABObject)
  3372. lpWABObject->Release();
  3373. #endif
  3374. return retval;
  3375. }
  3376. BOOL PAB_IABContainerOpenEntry()
  3377. {
  3378. //DWORD nCells, counter;
  3379. BOOL Found = FALSE;
  3380. ULONG ulFlags = 0;
  3381. HRESULT hr = hrSuccess;
  3382. SCODE sc = SUCCESS_SUCCESS;
  3383. int retval=TRUE, NumEntries, NumProps;
  3384. unsigned int i = 0, idx = 0, cMaxProps =0, cEntries = 0, PropIndex;
  3385. char lpszInput[] = "Resolve THIS buddy!", lpszInput2[] = "Resolve THIS DL buddy!";
  3386. LPADRLIST lpAdrList = NULL;
  3387. FlagList rgFlagList;
  3388. LPFlagList lpFlagList = (LPFlagList)&rgFlagList;
  3389. LPADRBOOK lpAdrBook = NULL;
  3390. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  3391. LPABCONT lpPABCont= NULL,lpPABCont2= NULL;
  3392. LPABCONT lpDLCont= NULL;
  3393. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  3394. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  3395. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  3396. ULONG cbEid=0; // entry id of the entry being added
  3397. LPENTRYID lpEid=NULL;
  3398. char EntProp[10][BIG_BUF]; //MAX_PROP
  3399. ULONG cValues = 0, cValues2 = 0, ulObjType=NULL;
  3400. ULONG cRows = 0;
  3401. ULONG iEntry = 0;
  3402. ULONG cbLookupEID;
  3403. LPENTRYID lpLookupEID;
  3404. int k=0;
  3405. LPMAILUSER lpMailUser=NULL,lpMailUser2=NULL,lpDistList=NULL,lpDistList2=NULL;
  3406. LPMAPITABLE lpContentsTable = NULL;
  3407. LPSRowSet lpRowSet = NULL;
  3408. SPropValue PropValue[3] = {0}; // This value is 3 because we
  3409. // will be setting 3 properties:
  3410. // EmailAddress, DisplayName and
  3411. // AddressType.
  3412. SizedSPropTagArray(2, SPTArrayCols) = { 2, {PR_DISPLAY_NAME, PR_ENTRYID } };
  3413. LPSPropValue lpSPropValueAddress = NULL;
  3414. LPSPropValue lpSPropValueMailUser = NULL;
  3415. LPSPropValue lpSPropValueDistList = NULL;
  3416. LPSPropValue lpSPropValueEntryID = NULL;
  3417. LPSPropValue lpSPropValueDL = NULL;
  3418. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  3419. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  3420. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  3421. SizedSPropTagArray(1,SPTArrayDisplayName) = {1, {PR_DISPLAY_NAME} };
  3422. LUIOut(L1," ");
  3423. LUIOut(L1,"Running PAB_IABContainerOpenEntry");
  3424. LUIOut(L2,"-> Verifies IABContainer->ResolveNames is functional by performing the following:");
  3425. LUIOut(L2, " Calls SetProps followed by SaveChanges on a MailUser PR_DISPLAY_NAME using a test string, and checks...");
  3426. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  3427. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  3428. LUIOut(L2, " string to the original test string.");
  3429. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  3430. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  3431. LUIOut(L2, " Calls SetProps followed by SaveChanges on a DistList PR_DISPLAY_NAME using a test string, and checks...");
  3432. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  3433. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  3434. LUIOut(L2, " string to the original test string.");
  3435. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  3436. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  3437. LUIOut(L1," ");
  3438. if (!GetAB(OUT &lpAdrBook)) {
  3439. retval = FALSE;
  3440. goto out;
  3441. }
  3442. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  3443. assert(lpAdrBook != NULL);
  3444. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  3445. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  3446. if (HR_FAILED(hr)) {
  3447. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  3448. retval=FALSE;
  3449. goto out;
  3450. }
  3451. //
  3452. // Try to create a MailUser entry in the container
  3453. //
  3454. LUIOut(L2, "Creating a Mail User in the container");
  3455. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  3456. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  3457. assert(lpABCont != NULL);
  3458. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  3459. IN 0, //Flags
  3460. OUT &cValues,
  3461. OUT &lpSPropValueAddress);
  3462. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  3463. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  3464. retval=FALSE;
  3465. goto out;
  3466. }
  3467. // The returned value of PR_DEF_CREATE_MAILUSER is an
  3468. // EntryID which can be passed to CreateEntry
  3469. //
  3470. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  3471. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  3472. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  3473. IN 0,
  3474. OUT (LPMAPIPROP *) &lpMailUser);
  3475. if (HR_FAILED(hr)) {
  3476. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  3477. retval=FALSE;
  3478. goto out;
  3479. }
  3480. //
  3481. // Then set the properties
  3482. //
  3483. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  3484. cValues = 1; //# of props we are setting
  3485. /* lstrcpy(szDLTag,"Address1");
  3486. GetPrivateProfileString("CreateEntries",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  3487. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  3488. */
  3489. lstrcpy((LPTSTR)&(EntProp[0]), lpszInput);
  3490. LUIOut(L2,"MailUser Entry to Add: %s",EntProp[0]);
  3491. for (i=0; i<(int)cValues;i++)
  3492. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  3493. hr = lpMailUser->SetProps(IN cValues,
  3494. IN PropValue,
  3495. IN NULL);
  3496. if (HR_FAILED(hr)) {
  3497. LUIOut(L3,"MailUser->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  3498. retval=FALSE;
  3499. goto out;
  3500. }
  3501. else LUIOut(L3,"MailUser->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  3502. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  3503. if (HR_FAILED(hr)) {
  3504. LUIOut(L3,"MailUser->SaveChanges FAILED");
  3505. retval=FALSE;
  3506. goto out;
  3507. }
  3508. else LUIOut(L3,"MailUser->SaveChanges PASSED, entry added to PAB/WAB");
  3509. //
  3510. // Do a ResolveNames on the string
  3511. //
  3512. LUIOut(L2, "Retrieving the entry and verifying against what we tried to save.");
  3513. NumEntries = 1, NumProps = 1;
  3514. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  3515. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3516. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszInput;
  3517. lpFlagList->cFlags = 1;
  3518. lpFlagList->ulFlag[0] = MAPI_UNRESOLVED;
  3519. hr = lpABCont->ResolveNames(
  3520. (LPSPropTagArray)&SPTArrayCols, // tag set for disp_name and eid
  3521. 0, // ulFlags
  3522. lpAdrList,
  3523. lpFlagList);
  3524. if (HR_FAILED(hr)) {
  3525. LUIOut(L3,"ABContainer->ResolveNames call FAILED, returned 0x%x", hr);
  3526. retval=FALSE;
  3527. goto out;
  3528. }
  3529. else LUIOut(L3,"ABContainer->ResolveNames call PASSED");
  3530. switch((ULONG)*lpFlagList->ulFlag) {
  3531. case MAPI_AMBIGUOUS: {
  3532. LUIOut(L4, "ResolveNames returned the MAPI_AMBIGUOUS flag. Test FAILED");
  3533. retval = FALSE;
  3534. break;
  3535. }
  3536. case MAPI_RESOLVED: {
  3537. LUIOut(L4, "ResolveNames returned the MAPI_RESOLVED flag. Test PASSED");
  3538. break;
  3539. }
  3540. case MAPI_UNRESOLVED: {
  3541. LUIOut(L4, "ResolveNames returned the MAPI_UNRESOLVED flag. Test FAILED");
  3542. retval = FALSE;
  3543. break;
  3544. }
  3545. default: {
  3546. LUIOut(L4, "Undefined flag value [%i] returned. Test FAILED", (ULONG)lpFlagList->ulFlag);
  3547. retval = FALSE;
  3548. }
  3549. }
  3550. // Search through returned AdrList for our entry
  3551. VerifyResolvedAdrList(lpAdrList, lpszInput);
  3552. FindProp(&lpAdrList->aEntries[0],
  3553. PR_ENTRYID,
  3554. &PropIndex);
  3555. lpLookupEID = (ENTRYID*)lpAdrList->aEntries[0].rgPropVals[PropIndex].Value.bin.lpb;
  3556. cbLookupEID = lpAdrList->aEntries[0].rgPropVals[PropIndex].Value.bin.cb;
  3557. hr = lpABCont->OpenEntry( IN cbLookupEID,
  3558. IN lpLookupEID,
  3559. IN 0, // Interface
  3560. IN MAPI_BEST_ACCESS, // Flags
  3561. OUT &ulObjType,
  3562. OUT (LPUNKNOWN *) &lpMailUser2
  3563. );
  3564. if (HR_FAILED(hr)) {
  3565. LUIOut(L3,"OpenEntry FAILED");
  3566. retval=FALSE;
  3567. goto dl;
  3568. }
  3569. // Check to make sure the object type is what we expect
  3570. LUIOut(L3, "Checking to make sure the returned object type is correct");
  3571. if (ulObjType != MAPI_MAILUSER) {
  3572. LUIOut(L2, "Object type is not MAPI_MAILUSER");
  3573. retval = FALSE;
  3574. goto out;
  3575. }
  3576. LUIOut(L3, "Object type is MAPI_MAILUSER");
  3577. // Call QueryInterface on the object
  3578. LUIOut(L3, "Calling QueryInterface on the returned object");
  3579. hr = (lpMailUser2->QueryInterface((REFIID)(IID_IMailUser), (VOID **) &lpABCont2));
  3580. if (HR_FAILED(hr)) {
  3581. LUIOut(L2, "QueryInterface on IID_IMailUser FAILED");
  3582. retval = FALSE;
  3583. goto out;
  3584. }
  3585. else LUIOut(L3, "QueryInterface on IID_IMailUser PASSED");
  3586. LUIOut(L3, "Trying to release the object QI returned");
  3587. if(lpABCont2) {
  3588. if ((LPUNKNOWN)(lpABCont2)->Release() <= 0)
  3589. LUIOut(L3, "QueryInterface returned a valid ptr and released succesfully");
  3590. else {
  3591. LUIOut(L2, "Release FAILED:returned a > zero ref count");
  3592. }
  3593. lpABCont2 = NULL;
  3594. }
  3595. else {
  3596. LUIOut(L2, "QueryInterface did not return a valid ptr");
  3597. retval = FALSE;
  3598. goto out;
  3599. }
  3600. //
  3601. // Delete the test entry we created in the wab
  3602. //
  3603. hr = HrCreateEntryListFromID(lpWABObject,
  3604. IN cbLookupEID,
  3605. IN lpLookupEID,
  3606. OUT &lpEntryList);
  3607. if (HR_FAILED(hr)) {
  3608. LUIOut(L3,"Could not Create Entry List");
  3609. retval=FALSE;
  3610. goto out;
  3611. }
  3612. // Then pass the lpEntryList to DeleteEntries to delete ...
  3613. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  3614. if (HR_FAILED(hr)) {
  3615. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  3616. FreeEntryList(lpWABObject, &lpEntryList);
  3617. retval=FALSE;
  3618. goto out;
  3619. }
  3620. FreeEntryList(lpWABObject, &lpEntryList);
  3621. // Free lpAdrList and properties
  3622. FreeAdrList(lpWABObject, &lpAdrList);
  3623. dl:
  3624. #ifdef DISTLIST
  3625. //
  3626. // Try to create a DL entry in the container
  3627. //
  3628. LUIOut(L2, "Creating a Distribution List in the container");
  3629. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_DL property");
  3630. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_DL
  3631. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  3632. IN 0, //Flags
  3633. OUT &cValues,
  3634. OUT &lpSPropValueDL);
  3635. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  3636. LUIOut(L3,"GetProps failed for Default DL template");
  3637. retval=FALSE;
  3638. goto out;
  3639. }
  3640. // The returned value of PR_DEF_CREATE_DL is an
  3641. // EntryID which one can pass to CreateEntry
  3642. //
  3643. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  3644. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  3645. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  3646. IN 0,
  3647. OUT (LPMAPIPROP *) &lpDistList);
  3648. if (HR_FAILED(hr)) {
  3649. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  3650. retval=FALSE;
  3651. goto out;
  3652. }
  3653. //
  3654. // Then set the properties
  3655. //
  3656. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  3657. cValues = 1; //# of props we are setting
  3658. /* lstrcpy(szDLTag,"Name1");
  3659. GetPrivateProfileString("CreatePDL",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  3660. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  3661. */
  3662. lstrcpy((LPTSTR)EntProp[0], lpszInput2);
  3663. LUIOut(L2,"DistList Entry to Add: %s",EntProp[0]);
  3664. for (i=0; i<(int)cValues;i++)
  3665. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  3666. hr = lpDistList->SetProps(IN cValues,
  3667. IN PropValue,
  3668. IN NULL);
  3669. if (HR_FAILED(hr)) {
  3670. LUIOut(L3,"DistList->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  3671. retval=FALSE;
  3672. goto out;
  3673. }
  3674. else LUIOut(L3,"DistList->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  3675. hr = lpDistList->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  3676. if (HR_FAILED(hr)) {
  3677. LUIOut(L3,"DistList->SaveChanges FAILED");
  3678. retval=FALSE;
  3679. goto out;
  3680. }
  3681. else LUIOut(L3,"DistList->SaveChanges PASSED, entry added to PAB/WAB");
  3682. //
  3683. // Do a ResolveNames on the string
  3684. //
  3685. LUIOut(L2, "Retrieving the entry and verifying against what we tried to save.");
  3686. // use WAB Allocators here
  3687. #ifdef PAB
  3688. if (! (sc = MAPIAllocateBuffer(sizeof(ADRLIST) + sizeof(ADRENTRY), (void **)&lpAdrList))) {
  3689. #endif //PAB
  3690. #ifdef WAB
  3691. if (! (sc = lpWABObject->AllocateBuffer(sizeof(ADRLIST) + sizeof(ADRENTRY), (void **)&lpAdrList))) {
  3692. #endif //WAB
  3693. lpAdrList->cEntries = 1;
  3694. lpAdrList->aEntries[0].ulReserved1 = 0;
  3695. lpAdrList->aEntries[0].cValues = 1;
  3696. #ifdef PAB
  3697. if (! (sc = MAPIAllocateMore(sizeof(SPropValue), lpAdrList,
  3698. (void **)&lpAdrList->aEntries[0].rgPropVals))) {
  3699. #endif //WAB
  3700. #ifdef WAB
  3701. if (! (sc = lpWABObject->AllocateMore(sizeof(SPropValue), lpAdrList,
  3702. (void **)&lpAdrList->aEntries[0].rgPropVals))) {
  3703. #endif //WAB
  3704. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3705. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszInput2;
  3706. lpFlagList->cFlags = 1;
  3707. lpFlagList->ulFlag[0] = MAPI_UNRESOLVED;
  3708. hr = lpABCont->ResolveNames(
  3709. (LPSPropTagArray)&SPTArrayCols, // tag set for disp_name and eid
  3710. 0, // ulFlags
  3711. lpAdrList,
  3712. lpFlagList);
  3713. if (HR_FAILED(hr)) {
  3714. LUIOut(L3,"ABContainer->ResolveNames call FAILED, returned 0x%x", hr);
  3715. retval=FALSE;
  3716. goto out;
  3717. }
  3718. else LUIOut(L3,"ABContainer->ResolveNames call PASSED");
  3719. Found = FALSE;
  3720. // Search through returned AdrList for our entry
  3721. for(i=0; ((i<(int) lpAdrList->cEntries) && (!Found)); ++i) {
  3722. cMaxProps = (int)lpAdrList->aEntries[i].cValues;
  3723. //Check to see if Display Name exists
  3724. idx=0;
  3725. while((lpAdrList->aEntries[i].rgPropVals[idx].ulPropTag != PR_DISPLAY_NAME )
  3726. && retval) {
  3727. idx++;
  3728. if(idx == cMaxProps) {
  3729. LUIOut(L4, "PR_DISPLAY_NAME was not found in the lpAdrList");
  3730. retval = FALSE;
  3731. }
  3732. }
  3733. LUIOut(L4,"Display Name: %s",lpAdrList->aEntries[i].rgPropVals[idx].Value.LPSZ);
  3734. if (!lstrcmp(lpAdrList->aEntries[i].rgPropVals[idx].Value.LPSZ,lpszInput2)) {
  3735. LUIOut(L3, "Found the entry we just added");
  3736. Found = TRUE;
  3737. }
  3738. //Check to see if EntryID exists
  3739. LUIOut(L3, "Verifying a PR_ENTRYID entry exists in the PropertyTagArray");
  3740. idx=0;
  3741. while((lpAdrList->aEntries[i].rgPropVals[idx].ulPropTag != PR_ENTRYID )
  3742. && retval) {
  3743. idx++;
  3744. if(idx == cMaxProps) {
  3745. LUIOut(L4, "PR_ENTRYID was not found in the lpAdrList");
  3746. retval = FALSE;
  3747. }
  3748. }
  3749. if (!Found) LUIOut(L3, "Did not find the entry. Test FAILED");
  3750. if (idx < cMaxProps) LUIOut(L3, "EntryID found");
  3751. if (!(retval && Found)) retval = FALSE;
  3752. else {
  3753. // Store EID for call to OpenEntry
  3754. lpLookupEID = (ENTRYID*)lpAdrList->aEntries[i].rgPropVals[idx].Value.bin.lpb;
  3755. cbLookupEID = lpAdrList->aEntries[i].rgPropVals[idx].Value.bin.cb;
  3756. }
  3757. }
  3758. }
  3759. hr = lpABCont->OpenEntry( IN cbLookupEID,
  3760. IN lpLookupEID,
  3761. IN 0, // Interface
  3762. IN MAPI_BEST_ACCESS, // Flags
  3763. OUT &ulObjType,
  3764. OUT (LPUNKNOWN *) &lpDistList2
  3765. );
  3766. if (HR_FAILED(hr)) {
  3767. LUIOut(L3,"OpenEntry FAILED");
  3768. retval=FALSE;
  3769. //goto out;
  3770. }
  3771. // Check to make sure the object type is what we expect
  3772. LUIOut(L3, "Checking to make sure the returned object type is correct");
  3773. if (ulObjType != MAPI_DISTLIST) {
  3774. LUIOut(L2, "Object type is not MAPI_DISTLIST");
  3775. retval = FALSE;
  3776. goto out;
  3777. }
  3778. LUIOut(L3, "Object type is MAPI_DISTLIST");
  3779. // Call QueryInterface on the object
  3780. LUIOut(L3, "Calling QueryInterface on the returned object");
  3781. hr = (lpABCont->QueryInterface((REFIID)(IID_IDistList), (VOID **) &lpABCont2));
  3782. if (HR_FAILED(hr)) {
  3783. LUIOut(L2, "QueryInterface on IID_IDistList FAILED");
  3784. retval = FALSE;
  3785. goto out;
  3786. }
  3787. else LUIOut(L3, "QueryInterface on IID_IDistList PASSED");
  3788. LUIOut(L3, "Trying to release the object QI returned");
  3789. if(lpABCont2) {
  3790. if ((LPUNKNOWN)(lpABCont2)->Release() <= 0)
  3791. LUIOut(L3, "QueryInterface returned a valid ptr and released succesfully");
  3792. else {
  3793. LUIOut(L2, "Release FAILED:returned a > zero ref count");
  3794. }
  3795. lpABCont2 = NULL;
  3796. }
  3797. else {
  3798. LUIOut(L2, "QueryInterface did not return a valid ptr");
  3799. retval = FALSE;
  3800. goto out;
  3801. }
  3802. #ifdef PAB
  3803. MAPIFreeBuffer(lpAdrList);
  3804. #endif //PAB
  3805. #ifdef WAB
  3806. lpWABObject->FreeBuffer(lpAdrList);
  3807. #endif //WAB
  3808. }
  3809. #endif //DISTLIST
  3810. out:
  3811. // Free lpAdrList and properties
  3812. FreeAdrList(lpWABObject, &lpAdrList);
  3813. #ifdef PAB
  3814. if (lpEid)
  3815. MAPIFreeBuffer(lpEid);
  3816. if (lpEidPAB)
  3817. MAPIFreeBuffer(lpEidPAB);
  3818. if (lpSPropValueAddress)
  3819. MAPIFreeBuffer(lpSPropValueAddress);
  3820. if (lpSPropValueEntryID)
  3821. MAPIFreeBuffer(lpSPropValueEntryID);
  3822. if (lpSPropValueDL)
  3823. MAPIFreeBuffer(lpSPropValueDL);
  3824. #endif
  3825. #ifdef WAB
  3826. if (lpEid)
  3827. lpWABObject->FreeBuffer(lpEid);
  3828. if (lpEidPAB)
  3829. lpWABObject->FreeBuffer(lpEidPAB);
  3830. if (lpSPropValueAddress)
  3831. lpWABObject->FreeBuffer(lpSPropValueAddress);
  3832. if (lpSPropValueEntryID)
  3833. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  3834. if (lpSPropValueDL)
  3835. lpWABObject->FreeBuffer(lpSPropValueDL);
  3836. #endif
  3837. if (lpMailUser)
  3838. lpMailUser->Release();
  3839. if (lpMailUser2)
  3840. lpMailUser2->Release();
  3841. if (lpDistList)
  3842. lpDistList->Release();
  3843. if (lpDistList2)
  3844. lpDistList2->Release();
  3845. if (lpContentsTable)
  3846. lpContentsTable->Release();
  3847. if (lpPABCont)
  3848. lpPABCont->Release();
  3849. if (lpABCont)
  3850. lpABCont->Release();
  3851. if (lpDLCont)
  3852. lpDLCont->Release();
  3853. if (lpAdrBook)
  3854. lpAdrBook->Release();
  3855. #ifdef PAB
  3856. if (lpMAPISession)
  3857. lpMAPISession->Release();
  3858. MAPIUninitialize();
  3859. #endif
  3860. #ifdef WAB
  3861. if (lpWABObject)
  3862. lpWABObject->Release();
  3863. #endif
  3864. return retval;
  3865. }
  3866. BOOL PAB_IABAddress()
  3867. {
  3868. //DWORD nCells, counter;
  3869. HWND hwnd = glblhwnd;
  3870. ADRPARM AdrParms;
  3871. LPADRPARM lpAdrParms = &AdrParms;
  3872. LPADRLIST lpAdrList = NULL;
  3873. char lpszCaptionText[64], lpszDestWellsText[64];
  3874. char lpszDisplayName[MAXSTRING], lpszDisplayName2[MAXSTRING], lpszDisplayName3[MAXSTRING];
  3875. ULONG ulFlags = 0;
  3876. HRESULT hr = hrSuccess;
  3877. SCODE sc = SUCCESS_SUCCESS;
  3878. int retval=TRUE, NumEntries, NumProps;
  3879. unsigned int i = 0, idx = 0, cMaxProps =0, cEntries = 0;
  3880. ULONG rgFlagList[2];
  3881. LPFlagList lpFlagList = (LPFlagList)rgFlagList;
  3882. LPADRBOOK lpAdrBook = NULL;
  3883. LUIOut(L1," ");
  3884. LUIOut(L1,"Running PAB_IABAddress");
  3885. LUIOut(L2,"-> Verifies IABContainer->ResolveNames is functional by performing the following:");
  3886. LUIOut(L2, " Calls SetProps followed by SaveChanges on a MailUser PR_DISPLAY_NAME using a test string, and checks...");
  3887. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  3888. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  3889. LUIOut(L2, " string to the original test string.");
  3890. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  3891. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  3892. LUIOut(L2, " Calls SetProps followed by SaveChanges on a DistList PR_DISPLAY_NAME using a test string, and checks...");
  3893. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  3894. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  3895. LUIOut(L2, " string to the original test string.");
  3896. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  3897. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  3898. LUIOut(L1," ");
  3899. if (!GetAB(OUT &lpAdrBook)) {
  3900. retval = FALSE;
  3901. goto out;
  3902. }
  3903. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  3904. assert(lpAdrBook != NULL);
  3905. //
  3906. // MULTISELECT MODE - To well only
  3907. //
  3908. // Fill in the ADRPARM structure
  3909. ZeroMemory(lpAdrParms, sizeof(ADRPARM));
  3910. NumEntries = 3, NumProps = 2;
  3911. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  3912. strcpy(lpszDisplayName, "Abraham Lincoln");
  3913. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3914. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszDisplayName;
  3915. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  3916. lpAdrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
  3917. strcpy(lpszDisplayName2, "Carl Sagon");
  3918. lpAdrList->aEntries[1].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3919. lpAdrList->aEntries[1].rgPropVals[0].Value.LPSZ = lpszDisplayName2;
  3920. lpAdrList->aEntries[1].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  3921. lpAdrList->aEntries[1].rgPropVals[1].Value.l = MAPI_TO;
  3922. strcpy(lpszDisplayName3, "Ren & Stimpy");
  3923. lpAdrList->aEntries[2].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3924. lpAdrList->aEntries[2].rgPropVals[0].Value.LPSZ = lpszDisplayName3;
  3925. lpAdrList->aEntries[2].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  3926. lpAdrList->aEntries[2].rgPropVals[1].Value.l = MAPI_TO;
  3927. LUIOut(L2, "Calling IABAddress with multiselect mode and only the To well");
  3928. MessageBox(NULL, "Calling IAB->Address in multi-select mode with To: well only. You should see 3 entries in the To: well.",
  3929. "WAB Test Harness", MB_OK);
  3930. lpAdrParms->ulFlags = ( DIALOG_MODAL );
  3931. strcpy(lpszCaptionText, "WABTEST - MultiSelect mode");
  3932. strcpy(lpszDestWellsText, "WABTEST - Destination well text");
  3933. lpAdrParms->lpszCaption = lpszCaptionText;
  3934. lpAdrParms->lpszDestWellsTitle = lpszDestWellsText;
  3935. lpAdrParms->cDestFields = 1;
  3936. hr = lpAdrBook->Address((ULONG*)&hwnd, lpAdrParms, &lpAdrList);
  3937. if (HR_FAILED(hr)) {
  3938. LUIOut(L2, "IAdrBook->Address call FAILED");
  3939. retval = FALSE;
  3940. goto out;
  3941. }
  3942. else LUIOut(L3, "IAdrBook->Address call PASSED");
  3943. if (lpAdrList) DisplayAdrList(lpAdrList, lpAdrList->cEntries);
  3944. else {
  3945. LUIOut(L3, "IAdrBook->Address returned a NULL lpAdrList. No entries were selected.");
  3946. }
  3947. // Free lpAdrList and properties
  3948. FreeAdrList(lpWABObject, &lpAdrList);
  3949. if (MessageBox(NULL, "Did the multi-select UI display correctly?",
  3950. "WAB Test Harness", MB_YESNO) == IDNO) {
  3951. LUIOut(L3, "Test operator reports the UI did not display correctly. Test FAILED");
  3952. retval = FALSE;
  3953. goto out;
  3954. }
  3955. //
  3956. // MULTISELECT MODE - To and CC wells only
  3957. //
  3958. // Fill in the ADRPARM structure
  3959. ZeroMemory(lpAdrParms, sizeof(ADRPARM));
  3960. NumEntries = 3, NumProps = 2;
  3961. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  3962. strcpy(lpszDisplayName, "Abraham Lincoln");
  3963. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3964. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszDisplayName;
  3965. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  3966. lpAdrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
  3967. strcpy(lpszDisplayName2, "Carl Sagon");
  3968. lpAdrList->aEntries[1].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3969. lpAdrList->aEntries[1].rgPropVals[0].Value.LPSZ = lpszDisplayName2;
  3970. lpAdrList->aEntries[1].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  3971. lpAdrList->aEntries[1].rgPropVals[1].Value.l = MAPI_CC;
  3972. strcpy(lpszDisplayName3, "Ren & Stimpy");
  3973. lpAdrList->aEntries[2].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  3974. lpAdrList->aEntries[2].rgPropVals[0].Value.LPSZ = lpszDisplayName3;
  3975. lpAdrList->aEntries[2].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  3976. lpAdrList->aEntries[2].rgPropVals[1].Value.l = MAPI_BCC;
  3977. LUIOut(L2, "Calling IABAddress with multiselect mode and both To and CC wells");
  3978. MessageBox(NULL, "Calling IAB->Address in multi-select mode with both To: and CC: wells. You should see 1 entry in each of the wells.",
  3979. "WAB Test Harness", MB_OK);
  3980. lpAdrParms->ulFlags = ( DIALOG_MODAL );
  3981. strcpy(lpszCaptionText, "WABTEST - MultiSelect mode");
  3982. strcpy(lpszDestWellsText, "WABTEST - Destination well text");
  3983. lpAdrParms->lpszCaption = lpszCaptionText;
  3984. lpAdrParms->lpszDestWellsTitle = lpszDestWellsText;
  3985. lpAdrParms->cDestFields = 2;
  3986. hr = lpAdrBook->Address((ULONG*)&hwnd, lpAdrParms, &lpAdrList);
  3987. if (HR_FAILED(hr)) {
  3988. LUIOut(L2, "IAdrBook->Address call FAILED");
  3989. retval = FALSE;
  3990. goto out;
  3991. }
  3992. else LUIOut(L3, "IAdrBook->Address call PASSED");
  3993. if (lpAdrList) DisplayAdrList(lpAdrList, lpAdrList->cEntries);
  3994. else {
  3995. LUIOut(L3, "IAdrBook->Address returned a NULL lpAdrList. No entries were selected.");
  3996. }
  3997. // Free lpAdrList and properties
  3998. FreeAdrList(lpWABObject, &lpAdrList);
  3999. if (MessageBox(NULL, "Did the multi-select UI display correctly?",
  4000. "WAB Test Harness", MB_YESNO) == IDNO) {
  4001. LUIOut(L3, "Test operator reports the UI did not display correctly. Test FAILED");
  4002. retval = FALSE;
  4003. goto out;
  4004. }
  4005. //
  4006. // MULTISELECT MODE - To, CC and BCC wells
  4007. //
  4008. // Fill in the ADRPARM structure
  4009. ZeroMemory(lpAdrParms, sizeof(ADRPARM));
  4010. NumEntries = 3, NumProps = 2;
  4011. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  4012. strcpy(lpszDisplayName, "Abraham Lincoln");
  4013. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4014. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszDisplayName;
  4015. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4016. lpAdrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
  4017. strcpy(lpszDisplayName2, "Carl Sagon");
  4018. lpAdrList->aEntries[1].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4019. lpAdrList->aEntries[1].rgPropVals[0].Value.LPSZ = lpszDisplayName2;
  4020. lpAdrList->aEntries[1].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4021. lpAdrList->aEntries[1].rgPropVals[1].Value.l = MAPI_CC;
  4022. strcpy(lpszDisplayName3, "Ren & Stimpy");
  4023. lpAdrList->aEntries[2].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4024. lpAdrList->aEntries[2].rgPropVals[0].Value.LPSZ = lpszDisplayName3;
  4025. lpAdrList->aEntries[2].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4026. lpAdrList->aEntries[2].rgPropVals[1].Value.l = MAPI_BCC;
  4027. LUIOut(L2, "Calling IABAddress with multiselect mode and To, CC and BCC wells");
  4028. MessageBox(NULL, "Calling IAB->Address in multi-select mode with To:, CC: and BCC: wells. You should see 1 entry in each well.",
  4029. "WAB Test Harness", MB_OK);
  4030. lpAdrParms->ulFlags = ( DIALOG_MODAL );
  4031. strcpy(lpszCaptionText, "WABTEST - MultiSelect mode");
  4032. strcpy(lpszDestWellsText, "WABTEST - Destination well text");
  4033. lpAdrParms->lpszCaption = lpszCaptionText;
  4034. lpAdrParms->lpszDestWellsTitle = lpszDestWellsText;
  4035. lpAdrParms->cDestFields = 3;
  4036. hr = lpAdrBook->Address((ULONG*)&hwnd, lpAdrParms, &lpAdrList);
  4037. if (HR_FAILED(hr)) {
  4038. LUIOut(L2, "IAdrBook->Address call FAILED");
  4039. retval = FALSE;
  4040. goto out;
  4041. }
  4042. else LUIOut(L3, "IAdrBook->Address call PASSED");
  4043. if (lpAdrList) DisplayAdrList(lpAdrList, lpAdrList->cEntries);
  4044. else {
  4045. LUIOut(L3, "IAdrBook->Address returned a NULL lpAdrList. No entries were selected.");
  4046. }
  4047. // Free lpAdrList and properties
  4048. FreeAdrList(lpWABObject, &lpAdrList);
  4049. if (MessageBox(NULL, "Did the multi-select UI display correctly?",
  4050. "WAB Test Harness", MB_YESNO) == IDNO) {
  4051. LUIOut(L3, "Test operator reports the UI did not display correctly. Test FAILED");
  4052. retval = FALSE;
  4053. goto out;
  4054. }
  4055. //
  4056. // BROWSE MODE - Modal
  4057. //
  4058. ZeroMemory(lpAdrParms, sizeof(ADRPARM));
  4059. NumEntries = 2, NumProps = 2;
  4060. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  4061. strcpy(lpszDisplayName, "Abraham Lincoln");
  4062. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4063. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszDisplayName;
  4064. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4065. lpAdrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
  4066. strcpy(lpszDisplayName2, "Carl Sagon");
  4067. lpAdrList->aEntries[1].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4068. lpAdrList->aEntries[1].rgPropVals[0].Value.LPSZ = lpszDisplayName2;
  4069. lpAdrList->aEntries[1].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4070. lpAdrList->aEntries[1].rgPropVals[1].Value.l = MAPI_CC;
  4071. LUIOut(L2, "Calling IABAddress with browse mode (modal)");
  4072. MessageBox(NULL, "Calling IAB->Address in browse mode with the modal flag set.",
  4073. "WAB Test Harness", MB_OK);
  4074. lpAdrParms->ulFlags = ( DIALOG_MODAL );
  4075. strcpy(lpszCaptionText, "WABTEST - Browse mode (modal)");
  4076. lpAdrParms->lpszCaption = lpszCaptionText;
  4077. lpAdrParms->cDestFields = 0;
  4078. hr = lpAdrBook->Address((ULONG*)&hwnd, lpAdrParms, &lpAdrList);
  4079. if (HR_FAILED(hr)) {
  4080. LUIOut(L2, "IAdrBook->Address call FAILED");
  4081. retval = FALSE;
  4082. goto out;
  4083. }
  4084. else LUIOut(L3, "IAdrBook->Address call PASSED");
  4085. // Free lpAdrList and properties
  4086. FreeAdrList(lpWABObject, &lpAdrList);
  4087. if (MessageBox(NULL, "Did the modal, browse UI display correctly?",
  4088. "WAB Test Harness", MB_YESNO) == IDNO) {
  4089. LUIOut(L3, "Test operator reports the UI did not display correctly. Test FAILED");
  4090. retval = FALSE;
  4091. goto out;
  4092. }
  4093. //
  4094. // BROWSE MODE - Modeless
  4095. //
  4096. ZeroMemory(lpAdrParms, sizeof(ADRPARM));
  4097. NumEntries = 2, NumProps = 2;
  4098. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  4099. strcpy(lpszDisplayName, "Abraham Lincoln");
  4100. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4101. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszDisplayName;
  4102. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4103. lpAdrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
  4104. strcpy(lpszDisplayName2, "Carl Sagon");
  4105. lpAdrList->aEntries[1].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4106. lpAdrList->aEntries[1].rgPropVals[0].Value.LPSZ = lpszDisplayName2;
  4107. lpAdrList->aEntries[1].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4108. lpAdrList->aEntries[1].rgPropVals[1].Value.l = MAPI_CC;
  4109. LUIOut(L2, "Calling IABAddress with browse mode (modeless)");
  4110. MessageBox(NULL, "Calling IAB->Address in browse mode with the SDI (modeless) flag set.",
  4111. "WAB Test Harness", MB_OK);
  4112. lpAdrParms->ulFlags = ( DIALOG_SDI );
  4113. strcpy(lpszCaptionText, "WABTEST - Browse mode (modeless)");
  4114. lpAdrParms->lpszCaption = lpszCaptionText;
  4115. lpAdrParms->cDestFields = 0;
  4116. hr = lpAdrBook->Address((ULONG*)&hwnd, lpAdrParms, &lpAdrList);
  4117. if (HR_FAILED(hr)) {
  4118. LUIOut(L2, "IAdrBook->Address call FAILED");
  4119. retval = FALSE;
  4120. goto out;
  4121. }
  4122. else LUIOut(L3, "IAdrBook->Address call PASSED");
  4123. //Reset the hwnd as the modeless call returns the hwnd of the modeless dialog
  4124. hwnd = glblhwnd;
  4125. // Free lpAdrList and properties
  4126. FreeAdrList(lpWABObject, &lpAdrList);
  4127. if (MessageBox(NULL, "Did the modeless, browse UI display correctly?",
  4128. "WAB Test Harness", MB_YESNO) == IDNO) {
  4129. LUIOut(L3, "Test operator reports the UI did not display correctly. Test FAILED");
  4130. retval = FALSE;
  4131. goto out;
  4132. }
  4133. //
  4134. // SINGLESELECT MODE
  4135. //
  4136. NumEntries = 1, NumProps = 2;
  4137. AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList);
  4138. strcpy(lpszDisplayName, "Abraham Lincoln");
  4139. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4140. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszDisplayName;
  4141. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
  4142. lpAdrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
  4143. LUIOut(L2, "Calling IABAddress with single select mode");
  4144. MessageBox(NULL, "Calling IAB->Address in single select mode.",
  4145. "WAB Test Harness", MB_OK);
  4146. lpAdrParms->ulFlags = ( DIALOG_MODAL | ADDRESS_ONE );
  4147. strcpy(lpszCaptionText, "WABTEST - SingleSelect mode");
  4148. lpAdrParms->lpszCaption = lpszCaptionText;
  4149. lpAdrParms->cDestFields = 0;
  4150. hr = lpAdrBook->Address((ULONG*)&hwnd, lpAdrParms, &lpAdrList);
  4151. if (HR_FAILED(hr)) {
  4152. LUIOut(L2, "IAdrBook->Address call FAILED");
  4153. retval = FALSE;
  4154. goto out;
  4155. }
  4156. else LUIOut(L3, "IAdrBook->Address call PASSED");
  4157. if (lpAdrList) DisplayAdrList(lpAdrList, lpAdrList->cEntries);
  4158. else {
  4159. LUIOut(L3, "IAdrBook->Address returned a NULL lpAdrList. No entries were selected.");
  4160. }
  4161. // Free lpAdrList and properties
  4162. FreeAdrList(lpWABObject, &lpAdrList);
  4163. if (MessageBox(NULL, "Did the single select UI display correctly?",
  4164. "WAB Test Harness", MB_YESNO) == IDNO) {
  4165. LUIOut(L3, "Test operator reports the UI did not display correctly. Test FAILED");
  4166. retval = FALSE;
  4167. goto out;
  4168. }
  4169. out:
  4170. FreeAdrList(lpWABObject, &lpAdrList);
  4171. if (lpAdrBook)
  4172. lpAdrBook->Release();
  4173. #ifdef PAB
  4174. if (lpMAPISession)
  4175. lpMAPISession->Release();
  4176. MAPIUninitialize();
  4177. #endif
  4178. #ifdef WAB
  4179. if (lpWABObject)
  4180. lpWABObject->Release();
  4181. #endif
  4182. return retval;
  4183. }
  4184. BOOL ThreadStress(LPVOID lpThreadNum) {
  4185. HRESULT hr;
  4186. LPENTRYLIST lpEntryList=NULL;
  4187. LPADRBOOK lpLocalAdrBook;
  4188. LPVOID Reserved1 = NULL;
  4189. DWORD Reserved2 = 0;
  4190. LPWABOBJECT lpLocalWABObject;
  4191. BOOL retval = TRUE;
  4192. LPSPropValue lpSPropValueAddress = NULL, lpSCompareProps = NULL;
  4193. ULONG cValues = 0, cValues2 = 0, cbEidPAB = 0, ulObjType = 0;
  4194. LPENTRYID lpEidPAB = NULL;
  4195. LPABCONT lpABCont= NULL;
  4196. char szDLTag[SML_BUF], *lpszReturnName = NULL, *lpszDisplayName = NULL, **lpszDisplayNames;
  4197. char EntryBuf[MAX_BUF];
  4198. unsigned int NumEntries, Counter1, Counter2, StrLen1, PropIndex;
  4199. LPMAILUSER lpMailUser = NULL;
  4200. LPMAPITABLE lpTable = NULL;
  4201. LPSRowSet lpRows = NULL;
  4202. SRestriction Restriction;
  4203. SPropValue* lpPropValue;
  4204. SizedSPropTagArray(1, SPTArrayCols) = { 1, {PR_ENTRYID} };
  4205. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  4206. WAB_PARAM WP;
  4207. LUIOut(L2, "Thread #%i initializing.", *(int *)lpThreadNum);
  4208. ZeroMemory((void *)&WP, sizeof(WAB_PARAM));
  4209. WP.cbSize=sizeof(WAB_PARAM);
  4210. hr = WABOpen(&lpLocalAdrBook, &lpLocalWABObject, &WP, Reserved2);
  4211. if (HR_FAILED(hr)) {
  4212. LUIOut(L2,"WABOpen Failed");
  4213. retval=FALSE;
  4214. goto out;
  4215. }
  4216. //lpWABObject = lpLocalWABObject; //AllocateAdrList expects a global ptr to the WAB obj
  4217. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  4218. assert(lpLocalAdrBook != NULL);
  4219. hr = OpenPABID( IN lpLocalAdrBook, OUT &cbEidPAB,
  4220. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  4221. if (HR_FAILED(hr)) {
  4222. LUIOut(L2,"OpenPABID Failed");
  4223. retval=FALSE;
  4224. goto out;
  4225. }
  4226. //
  4227. // Try to create a MailUser entry in the container
  4228. //
  4229. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  4230. assert(lpABCont != NULL);
  4231. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  4232. IN 0, //Flags
  4233. OUT &cValues,
  4234. OUT &lpSPropValueAddress);
  4235. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  4236. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  4237. retval=FALSE;
  4238. goto out;
  4239. }
  4240. // The returned value of PR_DEF_CREATE_MAILUSER is an
  4241. // EntryID which can be passed to CreateEntry
  4242. //
  4243. // Retrieve user info from ini file
  4244. lstrcpy(szDLTag,"Address1");
  4245. GetPrivateProfileString("CreateEntriesStress",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  4246. NumEntries = GetPrivateProfileInt("CreateEntriesStress","NumCopies",0,INIFILENAME);
  4247. //Allocate an array of String pointers to hold the display names
  4248. lpszDisplayNames = (char**)LocalAlloc(LMEM_FIXED, NumEntries * sizeof(LPSTR));
  4249. lpszDisplayName = (char*)LocalAlloc(LMEM_FIXED, MAX_BUF*sizeof(char));
  4250. ParseIniBuffer(IN EntryBuf, IN 1, OUT lpszDisplayName);
  4251. StrLen1 = strlen(lpszDisplayName);
  4252. sprintf(&(lpszDisplayName[StrLen1]), " [Thread #%i] - ", *(int *)lpThreadNum);
  4253. LUIOut(L2, "Thread #%i adding %i entries", *(int *)lpThreadNum, NumEntries);
  4254. for (Counter1 = 0; Counter1 < NumEntries; Counter1++) {
  4255. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  4256. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  4257. IN 0,
  4258. OUT (LPMAPIPROP *) &lpMailUser);
  4259. if (HR_FAILED(hr)) {
  4260. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  4261. retval=FALSE;
  4262. goto out;
  4263. }
  4264. //
  4265. // Then set the properties
  4266. //
  4267. CreateProps(IN INIFILENAME, IN "Properties", OUT &lpPropValue, OUT &cValues, IN Counter1, IN &lpszDisplayName, OUT &lpszReturnName);
  4268. //Allocate space for the display name
  4269. lpszDisplayNames[Counter1] = (char*)LocalAlloc(LMEM_FIXED, (strlen(lpszReturnName)+1)*sizeof(char));
  4270. //Copy the DisplayName for use later
  4271. strcpy(lpszDisplayNames[Counter1], lpszReturnName);
  4272. //LUIOut(L2,"MailUser Entry to Add: %s",lpszDisplayName);
  4273. hr = lpMailUser->SetProps(IN cValues,
  4274. IN lpPropValue,
  4275. IN NULL);
  4276. if (HR_FAILED(hr)) {
  4277. LUIOut(L3,"MailUser->SetProps call FAILED for %s properties",lpszReturnName);
  4278. retval=FALSE;
  4279. goto out;
  4280. }
  4281. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  4282. if (HR_FAILED(hr)) {
  4283. LUIOut(L3,"MailUser->SaveChanges FAILED with error code 0x%x",hr);
  4284. retval=FALSE;
  4285. goto out;
  4286. }
  4287. // Now retrieve all the props and compare to what we expect
  4288. hr = lpMailUser->GetProps( IN (LPSPropTagArray) NULL, //Want all props
  4289. IN 0, //Flags
  4290. OUT &cValues2,
  4291. OUT &lpSCompareProps);
  4292. if ((HR_FAILED(hr))||(PropError(lpSCompareProps->ulPropTag, cValues))) {
  4293. LUIOut(L3,"GetProps FAILED for MailUser");
  4294. retval=FALSE;
  4295. goto out;
  4296. }
  4297. if (!CompareProps(lpPropValue, cValues, lpSCompareProps, cValues2)) {
  4298. retval=FALSE;
  4299. goto out;
  4300. }
  4301. //Free the SPropValue for use in the next loop
  4302. if (lpPropValue) {
  4303. for (unsigned int Prop = 0; Prop < cValues; Prop++) {
  4304. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_STRING8) {
  4305. if (lpPropValue[Prop].Value.LPSZ) {
  4306. LocalFree(lpPropValue[Prop].Value.LPSZ);
  4307. lpPropValue[Prop].Value.LPSZ = NULL;
  4308. }
  4309. }
  4310. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_BINARY) {
  4311. if (lpPropValue[Prop].Value.bin.lpb) {
  4312. LocalFree(lpPropValue[Prop].Value.bin.lpb);
  4313. lpPropValue[Prop].Value.bin.lpb = NULL;
  4314. }
  4315. }
  4316. }
  4317. LocalFree(lpPropValue);
  4318. lpPropValue=NULL;
  4319. }
  4320. if (lpSCompareProps) {
  4321. lpLocalWABObject->FreeBuffer(lpSCompareProps);
  4322. lpSCompareProps = NULL;
  4323. }
  4324. lpMailUser->Release();
  4325. lpMailUser = NULL;
  4326. }
  4327. //LUIOut(L2, "Thread #%i added %i entries with %i properties", *(int *)lpThreadNum, NumEntries, cValues);
  4328. if (retval) LUIOut(L2, "Thread #%i compared %i props. No differences found", *(int *)lpThreadNum, cValues);
  4329. //
  4330. // Verify each entry we added now exists in the WAB and then delete it
  4331. //
  4332. LUIOut(L2, "Thread #%i verifying and deleting %i entries", *(int *)lpThreadNum, NumEntries);
  4333. // Create a contents table to verify each added entry exists in the store
  4334. hr = lpABCont->GetContentsTable(ULONG(0), &lpTable);
  4335. if (HR_FAILED(hr)) {
  4336. LUIOut(L3,"ABContainer->GetContentsTable call FAILED, returned 0x%x", hr);
  4337. retval=FALSE;
  4338. goto out;
  4339. }
  4340. //else LUIOut(L3,"ABContainer->ResolveNames call PASSED");
  4341. // Allocate the SpropValue ptr in the restriction structure
  4342. lpLocalWABObject->AllocateBuffer(sizeof(SPropValue), (void**)&(Restriction.res.resProperty.lpProp));
  4343. Restriction.res.resProperty.lpProp = (SPropValue*)Restriction.res.resProperty.lpProp;
  4344. //Now walk the FlagList and make sure everything resolved, if it did then delete it now
  4345. for (Counter2 = 0; Counter2 < NumEntries; Counter2++) {
  4346. // Build the restriction structure to pass to lpTable->Restrict
  4347. //** For testing the fail case only, stub out for real testing
  4348. // lstrcpy(lpszDisplayNames[Counter2], "This should not match");
  4349. //**
  4350. Restriction.rt = RES_PROPERTY; //Property restriction
  4351. Restriction.res.resProperty.relop = RELOP_EQ; //Equals
  4352. Restriction.res.resProperty.ulPropTag = PR_DISPLAY_NAME;
  4353. Restriction.res.resProperty.lpProp->ulPropTag = PR_DISPLAY_NAME;
  4354. Restriction.res.resProperty.lpProp->Value.LPSZ = lpszDisplayNames[Counter2];
  4355. hr = lpTable->Restrict(&Restriction, ULONG(0));
  4356. if (HR_FAILED(hr)) {
  4357. LUIOut(L3,"Table->Restrict call FAILED, returned 0x%x", hr);
  4358. retval=FALSE;
  4359. goto out;
  4360. }
  4361. hr = lpTable->QueryRows(LONG(1),
  4362. ULONG(0),
  4363. &lpRows);
  4364. if (HR_FAILED(hr)) {
  4365. LUIOut(L3,"Table->QueryRows call FAILED: Entry #%i, returned 0x%x", Counter2, hr);
  4366. retval=FALSE;
  4367. goto out;
  4368. }
  4369. if (!lpRows->cRows) {
  4370. LUIOut(L2, "QueryRows did not find entry #%i. Test FAILED", Counter2);
  4371. retval=FALSE;
  4372. goto out;
  4373. }
  4374. //** For testing purposes only, stub out for real testing
  4375. //EnterCriticalSection(&CriticalSection);
  4376. //DisplayRows(lpRows);
  4377. //LeaveCriticalSection(&CriticalSection);
  4378. //**
  4379. // Change the EntryID to a LPENTRYLIST
  4380. FindPropinRow(&lpRows->aRow[0],
  4381. PR_ENTRYID,
  4382. &PropIndex);
  4383. hr = HrCreateEntryListFromID(lpLocalWABObject,
  4384. IN lpRows->aRow[0].lpProps[PropIndex].Value.bin.cb,
  4385. IN (ENTRYID*)lpRows->aRow[0].lpProps[PropIndex].Value.bin.lpb,
  4386. OUT &lpEntryList);
  4387. if (HR_FAILED(hr)) {
  4388. LUIOut(L3,"Could not Create Entry List");
  4389. retval=FALSE;
  4390. goto out;
  4391. }
  4392. // Then pass the lpEntryList to DeleteEntries to delete ...
  4393. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  4394. if (HR_FAILED(hr)) {
  4395. LUIOut(L3,"Could not Delete Entry %i. DeleteEntry returned 0x%x", Counter2, hr);
  4396. FreeEntryList(lpLocalWABObject, &lpEntryList);
  4397. retval=FALSE;
  4398. goto out;
  4399. }
  4400. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  4401. // Verify the entry was deleted by calling QueryRows again
  4402. hr = lpTable->QueryRows(LONG(1),
  4403. ULONG(0),
  4404. &lpRows);
  4405. if (HR_FAILED(hr)) {
  4406. LUIOut(L3,"Table->QueryRows call FAILED: Entry #%i, returned 0x%x", Counter2, hr);
  4407. retval=FALSE;
  4408. goto out;
  4409. }
  4410. if (lpRows->cRows) { // Should be 0 if deleted
  4411. LUIOut(L2, "Thread #%i: QueryRows found entry #%i even tho it was deleted. Test FAILED", *(int *)lpThreadNum, Counter2);
  4412. retval=FALSE;
  4413. goto out;
  4414. }
  4415. //Cleanup
  4416. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from second call to queryrows
  4417. if (lpEntryList) {
  4418. FreeEntryList(lpLocalWABObject, &lpEntryList);
  4419. lpEntryList = NULL;
  4420. }
  4421. LocalFree((HLOCAL)lpszDisplayNames[Counter2]);
  4422. lpszDisplayNames[Counter2] = NULL;
  4423. }
  4424. out:
  4425. if (lpszDisplayName) {
  4426. LocalFree(lpszDisplayName);
  4427. lpszDisplayName = NULL;
  4428. }
  4429. if (lpPropValue) {
  4430. for (unsigned int Prop = 0; Prop < cValues; Prop++) {
  4431. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_STRING8) {
  4432. if (lpPropValue[Prop].Value.LPSZ) {
  4433. LocalFree(lpPropValue[Prop].Value.LPSZ);
  4434. lpPropValue[Prop].Value.LPSZ = NULL;
  4435. }
  4436. }
  4437. if (PROP_TYPE(lpPropValue[Prop].ulPropTag) == PT_BINARY) {
  4438. if (lpPropValue[Prop].Value.bin.lpb) {
  4439. LocalFree(lpPropValue[Prop].Value.bin.lpb);
  4440. lpPropValue[Prop].Value.bin.lpb = NULL;
  4441. }
  4442. }
  4443. }
  4444. LocalFree(lpPropValue);
  4445. lpPropValue=NULL;
  4446. }
  4447. if (lpEntryList) {
  4448. FreeEntryList(lpLocalWABObject, &lpEntryList);
  4449. lpEntryList = NULL;
  4450. }
  4451. if (Restriction.res.resProperty.lpProp) {
  4452. lpLocalWABObject->FreeBuffer(Restriction.res.resProperty.lpProp);
  4453. Restriction.res.resProperty.lpProp = NULL;
  4454. }
  4455. if (lpszDisplayNames) {
  4456. for (unsigned int FreeCounter = 0; FreeCounter < NumEntries; FreeCounter++) {
  4457. if (lpszDisplayNames[FreeCounter]) LocalFree((HLOCAL)lpszDisplayNames[FreeCounter]);
  4458. }
  4459. LocalFree((HLOCAL)lpszDisplayNames);
  4460. }
  4461. FreeRows(lpLocalWABObject, &lpRows);
  4462. #ifdef PAB
  4463. if (lpEidPAB)
  4464. MAPIFreeBuffer(lpEidPAB);
  4465. if (lpSPropValueAddress)
  4466. MAPIFreeBuffer(lpSPropValueAddress);
  4467. #endif
  4468. #ifdef WAB
  4469. if (lpEidPAB)
  4470. lpLocalWABObject->FreeBuffer(lpEidPAB);
  4471. if (lpSCompareProps) {
  4472. lpLocalWABObject->FreeBuffer(lpSCompareProps);
  4473. lpSCompareProps = NULL;
  4474. }
  4475. if (lpSPropValueAddress)
  4476. lpLocalWABObject->FreeBuffer(lpSPropValueAddress);
  4477. #endif
  4478. if (lpTable)
  4479. lpTable->Release();
  4480. if (lpMailUser)
  4481. lpMailUser->Release();
  4482. if (lpABCont)
  4483. lpABCont->Release();
  4484. if (lpLocalAdrBook)
  4485. lpLocalAdrBook->Release();
  4486. #ifdef PAB
  4487. if (lpMAPISession)
  4488. lpMAPISession->Release();
  4489. MAPIUninitialize();
  4490. #endif
  4491. #ifdef WAB
  4492. if (lpLocalWABObject)
  4493. lpLocalWABObject->Release();
  4494. #endif
  4495. return(retval);
  4496. }
  4497. BOOL ThreadManager()
  4498. {
  4499. int NumReps, NumThreads, Counter1, Counter2, Counter3;
  4500. BOOL retval = TRUE;
  4501. HANDLE *lpThreads; //ptr to Array of thread handles
  4502. int * lpThreadParams; //ptr to Array of params passed to threads
  4503. DWORD ThreadId; //Don't care about thread IDs so it gets overwritten each time
  4504. DWORD ThreadRetVal;
  4505. // how many reps and threads
  4506. // Retrieve user info from ini file
  4507. InitializeCriticalSection(&CriticalSection);
  4508. NumReps = GetPrivateProfileInt("CreateEntriesStress","NumReps",1,INIFILENAME);
  4509. NumThreads = GetPrivateProfileInt("CreateEntriesStress","NumThreads",3,INIFILENAME);
  4510. LUIOut(L1, "ThreadManager: Preparing to run %i repititions with %i threads each",
  4511. NumReps, NumThreads);
  4512. // allocate lpThreads for NumThreads
  4513. lpThreads = (HANDLE*)LocalAlloc(LMEM_FIXED, NumThreads * sizeof(HANDLE));
  4514. lpThreadParams = (int*)LocalAlloc(LMEM_FIXED, NumThreads * sizeof(int));
  4515. if (lpThreads) {
  4516. for (Counter1 = 0; ((Counter1 < NumReps) || ((NumReps == 0) && (!glblStop))) && retval; Counter1++) {
  4517. for (Counter2 = 0; (Counter2 < NumThreads); Counter2++) {
  4518. lpThreadParams[Counter2] = Counter2;
  4519. lpThreads[Counter2] = CreateThread(
  4520. (LPSECURITY_ATTRIBUTES) NULL, // pointer to thread security attributes
  4521. (DWORD) 0, // initial thread stack size, in bytes
  4522. (LPTHREAD_START_ROUTINE) ThreadStress, // pointer to thread function
  4523. (LPVOID) &(lpThreadParams[Counter2]), // argument for new thread
  4524. (DWORD) 0, // creation flags
  4525. (LPDWORD) &ThreadId // pointer to returned thread identifier
  4526. );
  4527. if (!lpThreads[Counter2]) {
  4528. LUIOut(L1, "<ERROR> ThreadManager: Unable to create one of the helper threads");
  4529. retval = FALSE;
  4530. break; //We're outta here, just go on to cleanup the threads that launched
  4531. }
  4532. }
  4533. //Threads are off and running at this point
  4534. //Wait till they complete, collect retvals and cleanup
  4535. WaitForMultipleObjects(
  4536. (DWORD) (Counter2), // number of handles in handle array or
  4537. // partial if not all threads made it
  4538. lpThreads, // address of object-handle array
  4539. TRUE, // wait flag - TRUE = wait for all threads
  4540. INFINITE // time-out interval in milliseconds
  4541. );
  4542. //Check each thread for errors and then free the handles
  4543. for (Counter3 = 0; Counter3 < Counter2; Counter3++) {
  4544. GetExitCodeThread(
  4545. (HANDLE) lpThreads[Counter3], // handle to the thread
  4546. (LPDWORD) &ThreadRetVal // address to receive termination status
  4547. );
  4548. if (!(ThreadRetVal)) retval = FALSE;
  4549. CloseHandle(lpThreads[Counter3]);
  4550. }
  4551. }
  4552. DeleteCriticalSection(&CriticalSection);
  4553. LocalFree((HLOCAL)lpThreadParams);
  4554. LocalFree((HLOCAL)lpThreads);
  4555. }
  4556. else {
  4557. LUIOut(L1, "<ERROR> ThreadManager: Couldn't allocate the thread handle array.");
  4558. //Tell the app that ThreadManager has finished and pass back the return value in
  4559. //the HIWORD of the wParam - since we know it failed at this point, no need to
  4560. //stuff the HIWORD since it's already zero.
  4561. PostMessage(glblhwnd, WM_COMMAND, (WPARAM)ID_MULTITHREADCOMPLETE, (LPARAM)0);
  4562. return(FALSE);
  4563. }
  4564. //Tell the app that ThreadManager has finished and pass back the return value in
  4565. //the HIWORD of the wParam
  4566. PostMessage(glblhwnd, WM_COMMAND,
  4567. (WPARAM)(ID_MULTITHREADCOMPLETE | (retval << 16)), (LPARAM)0);
  4568. return(retval);
  4569. }
  4570. BOOL PAB_AddMultipleEntries()
  4571. {
  4572. //DWORD nCells, counter;
  4573. ULONG ulFlags = 0;
  4574. HRESULT hr = hrSuccess;
  4575. SCODE sc = SUCCESS_SUCCESS;
  4576. int retval=TRUE;
  4577. LPADRBOOK lpAdrBook = NULL;
  4578. LPABCONT lpABCont= NULL;
  4579. LPABCONT lpPABCont= NULL;
  4580. LPABCONT lpDLCont= NULL;
  4581. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  4582. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  4583. ULONG cbEid=0; // entry id of the entry being added
  4584. LPENTRYID lpEid=NULL;
  4585. char EntProp[10][BIG_BUF]; //MAX_PROP
  4586. ULONG cValues = 0, cValues2 = 0, ulObjType=NULL;
  4587. ULONG cRows = 0;
  4588. ULONG iEntry = 0;
  4589. int i=0,k=0;
  4590. char EntryBuf[MAX_BUF];
  4591. char szDLTag[SML_BUF];
  4592. unsigned int NumEntries, counter, StrLen;
  4593. LPMAILUSER lpMailUser=NULL,lpDistList=NULL;
  4594. SPropValue PropValue[3] = {0}; // This value is 3 because we
  4595. // will be setting 3 properties:
  4596. // EmailAddress, DisplayName and
  4597. // AddressType.
  4598. LPSPropValue lpSPropValueAddress = NULL;
  4599. LPSPropValue lpSPropValueDL = NULL;
  4600. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  4601. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  4602. LUIOut(L1," ");
  4603. LUIOut(L1,"Running PAB_AddMultipleEntries");
  4604. LUIOut(L1," ");
  4605. if (!GetAB(OUT &lpAdrBook)) {
  4606. retval = FALSE;
  4607. goto out;
  4608. }
  4609. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  4610. assert(lpAdrBook != NULL);
  4611. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  4612. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  4613. // hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  4614. if (HR_FAILED(hr)) {
  4615. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  4616. retval=FALSE;
  4617. goto out;
  4618. }
  4619. //
  4620. // Try to create a MailUser entry in the container
  4621. //
  4622. LUIOut(L2, "Creating a Mail User in the container");
  4623. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  4624. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  4625. assert(lpABCont != NULL);
  4626. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  4627. IN 0, //Flags
  4628. OUT &cValues,
  4629. OUT &lpSPropValueAddress);
  4630. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  4631. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  4632. retval=FALSE;
  4633. goto out;
  4634. }
  4635. // The returned value of PR_DEF_CREATE_MAILUSER is an
  4636. // EntryID which can be passed to CreateEntry
  4637. //
  4638. // Retrieve user info from ini file
  4639. cValues = 3; //# of props we are setting
  4640. lstrcpy(szDLTag,"Address1");
  4641. GetPrivateProfileString("CreateEntriesStress",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  4642. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  4643. StrLen = (strlen(EntProp[0]));
  4644. _itoa(0,(char*)&EntProp[0][StrLen],10);
  4645. EntProp[0][StrLen+1]= '\0';
  4646. NumEntries = GetPrivateProfileInt("CreateEntriesStress","NumCopies",0,INIFILENAME);
  4647. for (counter = 0; counter < NumEntries; counter++) {
  4648. // LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  4649. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  4650. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  4651. IN 0,
  4652. OUT (LPMAPIPROP *) &lpMailUser);
  4653. if (HR_FAILED(hr)) {
  4654. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  4655. retval=FALSE;
  4656. goto out;
  4657. }
  4658. //
  4659. // Then set the properties
  4660. //
  4661. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  4662. PropValue[1].ulPropTag = PR_ADDRTYPE;
  4663. PropValue[2].ulPropTag = PR_EMAIL_ADDRESS;
  4664. _itoa(counter,(char*)&EntProp[0][StrLen],10);
  4665. LUIOut(L2,"MailUser Entry to Add: %s",EntProp[0]);
  4666. for (i=0; i<(int)cValues;i++)
  4667. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  4668. hr = lpMailUser->SetProps(IN cValues,
  4669. IN PropValue,
  4670. IN NULL);
  4671. if (HR_FAILED(hr)) {
  4672. LUIOut(L3,"MailUser->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  4673. retval=FALSE;
  4674. goto out;
  4675. }
  4676. // else LUIOut(L3,"MailUser->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  4677. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  4678. if (HR_FAILED(hr)) {
  4679. LUIOut(L3,"MailUser->SaveChanges FAILED");
  4680. retval=FALSE;
  4681. goto out;
  4682. }
  4683. // else LUIOut(L3,"MailUser->SaveChanges PASSED, entry added to PAB/WAB");
  4684. if (lpMailUser) {
  4685. lpMailUser->Release();
  4686. lpMailUser = NULL;
  4687. }
  4688. }
  4689. #ifdef DISTLIST
  4690. //
  4691. // Try to create a DL entry in the container
  4692. //
  4693. LUIOut(L2, "Creating a Distribution List in the container");
  4694. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_DL property");
  4695. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_DL
  4696. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  4697. IN 0, //Flags
  4698. OUT &cValues,
  4699. OUT &lpSPropValueDL);
  4700. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  4701. LUIOut(L3,"GetProps failed for Default DL template");
  4702. retval=FALSE;
  4703. goto out;
  4704. }
  4705. // The returned value of PR_DEF_CREATE_DL is an
  4706. // EntryID which one can pass to CreateEntry
  4707. //
  4708. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  4709. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  4710. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  4711. IN 0,
  4712. OUT (LPMAPIPROP *) &lpDistList);
  4713. if (HR_FAILED(hr)) {
  4714. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  4715. retval=FALSE;
  4716. goto out;
  4717. }
  4718. //
  4719. // Then set the properties
  4720. //
  4721. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  4722. cValues = 1; //# of props we are setting
  4723. lstrcpy(szDLTag,"Name1");
  4724. GetPrivateProfileString("CreatePDL",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  4725. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  4726. LUIOut(L2,"DistList Entry to Add: %s",EntProp[0]);
  4727. for (i=0; i<(int)cValues;i++)
  4728. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  4729. hr = lpDistList->SetProps(IN cValues,
  4730. IN PropValue,
  4731. IN NULL);
  4732. if (HR_FAILED(hr)) {
  4733. LUIOut(L3,"DistList->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  4734. retval=FALSE;
  4735. goto out;
  4736. }
  4737. else LUIOut(L3,"DistList->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  4738. hr = lpDistList->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  4739. if (HR_FAILED(hr)) {
  4740. LUIOut(L3,"DistList->SaveChanges FAILED");
  4741. retval=FALSE;
  4742. goto out;
  4743. }
  4744. else LUIOut(L3,"DistList->SaveChanges PASSED, entry added to PAB/WAB");
  4745. #endif DISTLIST
  4746. out:
  4747. #ifdef PAB
  4748. if (lpEid)
  4749. MAPIFreeBuffer(lpEid);
  4750. if (lpEidPAB)
  4751. MAPIFreeBuffer(lpEidPAB);
  4752. if (lpSPropValueAddress)
  4753. MAPIFreeBuffer(lpSPropValueAddress);
  4754. if (lpSPropValueDL)
  4755. MAPIFreeBuffer(lpSPropValueDL);
  4756. #endif
  4757. #ifdef WAB
  4758. if (lpEid)
  4759. lpWABObject->FreeBuffer(lpEid);
  4760. if (lpEidPAB)
  4761. lpWABObject->FreeBuffer(lpEidPAB);
  4762. if (lpSPropValueAddress)
  4763. lpWABObject->FreeBuffer(lpSPropValueAddress);
  4764. if (lpSPropValueDL)
  4765. lpWABObject->FreeBuffer(lpSPropValueDL);
  4766. #endif
  4767. if (lpMailUser)
  4768. lpMailUser->Release();
  4769. if (lpDistList)
  4770. lpDistList->Release();
  4771. if (lpPABCont)
  4772. lpPABCont->Release();
  4773. if (lpABCont)
  4774. lpABCont->Release();
  4775. if (lpDLCont)
  4776. lpDLCont->Release();
  4777. if (lpAdrBook)
  4778. lpAdrBook->Release();
  4779. #ifdef PAB
  4780. if (lpMAPISession)
  4781. lpMAPISession->Release();
  4782. MAPIUninitialize();
  4783. #endif
  4784. #ifdef WAB
  4785. if (lpWABObject)
  4786. lpWABObject->Release();
  4787. #endif
  4788. return retval;
  4789. }
  4790. BOOL PAB_IABResolveName()
  4791. {
  4792. //DWORD nCells, counter;
  4793. char lpTitleText[64];
  4794. BOOL Found = FALSE;
  4795. ULONG ulFlags = 0;
  4796. HRESULT hr = hrSuccess;
  4797. SCODE sc = SUCCESS_SUCCESS;
  4798. int retval=TRUE;
  4799. unsigned int i = 0, idx = 0, cMaxProps =0, cEntries = 0;
  4800. ENTRYLIST* lpEntryList;
  4801. char lpszMatch[MAXSTRING], lpszNoMatch[MAXSTRING], lpszOneOff[MAXSTRING], lpszOneOff2[MAXSTRING];
  4802. char lpszMatchDisplayName[MAXSTRING], lpszMatchAddrType[MAXSTRING], lpszMatchEmailAddress[MAXSTRING];
  4803. char lpszOneOff2DisplayName[MAXSTRING], lpszOneOff2EmailAddress[MAXSTRING];
  4804. char lpszOneOffDisplayName[MAXSTRING], lpszOneOffEmailAddress[MAXSTRING];
  4805. LPADRLIST lpAdrList = NULL;
  4806. ULONG rgFlagList[2];
  4807. LPFlagList lpFlagList = (LPFlagList)rgFlagList;
  4808. LPADRBOOK lpAdrBook = NULL;
  4809. LPABCONT lpABCont = NULL;
  4810. LPABCONT lpDLCont = NULL;
  4811. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  4812. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL, lpLookupEID=NULL;
  4813. ULONG cbLookupEID, cValues = 0, cValues2 = 0, ulObjType=NULL;
  4814. int k=0, NumEntries, NumProps;
  4815. LPMAILUSER lpMailUser=NULL,lpDistList=NULL;
  4816. SPropValue PropValue[3] = {0}; // This value is 3 because we
  4817. // will be setting 3 properties:
  4818. // EmailAddress, DisplayName and
  4819. // AddressType.
  4820. SizedSPropTagArray(2, SPTArrayCols) = { 2, {PR_DISPLAY_NAME, PR_ENTRYID } };
  4821. LPSPropValue lpSPropValueAddress = NULL;
  4822. LPSPropValue lpSPropValueMailUser = NULL;
  4823. LPSPropValue lpSPropValueDistList = NULL;
  4824. LPSPropValue lpSPropValueEntryID = NULL;
  4825. LPSPropValue lpSPropValueDL = NULL;
  4826. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  4827. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  4828. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  4829. SizedSPropTagArray(1,SPTArrayDisplayName) = {1, {PR_DISPLAY_NAME} };
  4830. LUIOut(L1," ");
  4831. LUIOut(L1,"Running PAB_IABResolveName");
  4832. LUIOut(L2,"-> Verifies IAdrBook->ResolveNames is functional by performing the following:");
  4833. LUIOut(L2, " Calls SetProps followed by SaveChanges on a MailUser PR_DISPLAY_NAME using a test string, and checks...");
  4834. LUIOut(L2, " # Verifies the resolve UI is displayed when it should be by asking the test operator.");
  4835. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  4836. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  4837. LUIOut(L2, " string to the original test string.");
  4838. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  4839. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  4840. LUIOut(L2, " Calls SetProps followed by SaveChanges on a DistList PR_DISPLAY_NAME using a test string, and checks...");
  4841. LUIOut(L2, " # Verifies the resolve UI is displayed when it should be by asking the test operator.");
  4842. LUIOut(L2, " # The return code from ResolveNames (called with a PropertyTagArray containing PR_DISPLAY_NAME and PR_ENTRY_ID)");
  4843. LUIOut(L2, " # Walks the returned lpAdrList and checks each PropertyTagArray for PR_DISPLAY_NAME and then compares the ");
  4844. LUIOut(L2, " string to the original test string.");
  4845. LUIOut(L2, " # Walks the returned lpAdrList and verifies that an EntryID exists in each PropertyTagArray");
  4846. // LUIOut(L2, " # Verifies that the display name returned from GetProps is what we set");
  4847. LUIOut(L1," ");
  4848. if (!GetAB(OUT &lpAdrBook)) {
  4849. retval = FALSE;
  4850. goto out;
  4851. }
  4852. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  4853. assert(lpAdrBook != NULL);
  4854. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  4855. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  4856. if (HR_FAILED(hr)) {
  4857. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  4858. retval=FALSE;
  4859. goto out;
  4860. }
  4861. //
  4862. // Try to create a MailUser entry in the container
  4863. //
  4864. LUIOut(L2, "Creating a Mail User in the container");
  4865. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_MAILUSER property");
  4866. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_MAILUSER
  4867. assert(lpABCont != NULL);
  4868. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  4869. IN 0, //Flags
  4870. OUT &cValues,
  4871. OUT &lpSPropValueAddress);
  4872. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  4873. LUIOut(L3,"GetProps FAILED for Default MailUser template");
  4874. retval=FALSE;
  4875. goto out;
  4876. }
  4877. // The returned value of PR_DEF_CREATE_MAILUSER is an
  4878. // EntryID which can be passed to CreateEntry
  4879. //
  4880. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  4881. hr = lpABCont->CreateEntry( IN lpSPropValueAddress->Value.bin.cb,
  4882. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb,
  4883. IN 0,
  4884. OUT (LPMAPIPROP *) &lpMailUser);
  4885. if (HR_FAILED(hr)) {
  4886. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  4887. retval=FALSE;
  4888. goto out;
  4889. }
  4890. //
  4891. // Then set the properties
  4892. //
  4893. // Read in the ini file strings to resolve against
  4894. // Only adding 1 entry for the first ResName in the ini file
  4895. // but will attempt to resolve all ResNames in the multientry resolve case
  4896. GetPrivateProfileString("ResolveName","ResName1","no ini found",lpszMatch,MAXSTRING,INIFILENAME);
  4897. GetPrivateProfileString("ResolveName","NonExistentName","no ini found",lpszNoMatch,MAXSTRING,INIFILENAME);
  4898. GetPrivateProfileString("ResolveName","OneOffAddress","no ini found",lpszOneOff,MAXSTRING,INIFILENAME);
  4899. GetPrivateProfileString("ResolveName","OneOffAddress2","no ini found",lpszOneOff2,MAXSTRING,INIFILENAME);
  4900. ParseIniBuffer(lpszMatch, 1, lpszMatchDisplayName);
  4901. ParseIniBuffer(lpszMatch, 2, lpszMatchAddrType);
  4902. ParseIniBuffer(lpszMatch, 3, lpszMatchEmailAddress);
  4903. ParseIniBuffer(lpszOneOff2, 1, lpszOneOff2DisplayName);
  4904. ParseIniBuffer(lpszOneOff2, 3, lpszOneOff2EmailAddress);
  4905. ParseIniBuffer(lpszOneOff, 1, lpszOneOffDisplayName);
  4906. ParseIniBuffer(lpszOneOff, 3, lpszOneOffEmailAddress);
  4907. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  4908. PropValue[1].ulPropTag = PR_ADDRTYPE;
  4909. PropValue[2].ulPropTag = PR_EMAIL_ADDRESS;
  4910. PropValue[0].Value.LPSZ = lpszMatchDisplayName;
  4911. PropValue[1].Value.LPSZ = lpszMatchAddrType;
  4912. PropValue[2].Value.LPSZ = lpszMatchEmailAddress;
  4913. /*
  4914. cValues = 3; //# of props we are setting
  4915. GetPropsFromIniBufEntry(lpszMatch,cValues,EntProp);
  4916. //lstrcpy((LPTSTR)EntProp[0], lpszMatch);
  4917. LUIOut(L2,"MailUser Entry to Add: %s",EntProp[0]);
  4918. for (i=0; i<(int)cValues;i++)
  4919. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  4920. */
  4921. LUIOut(L2,"MailUser Entry to Add: %s",PropValue[0].Value.LPSZ);
  4922. hr = lpMailUser->SetProps(IN cValues,
  4923. IN PropValue,
  4924. IN NULL);
  4925. if (HR_FAILED(hr)) {
  4926. LUIOut(L3,"MailUser->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  4927. retval=FALSE;
  4928. goto out;
  4929. }
  4930. else LUIOut(L3,"MailUser->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  4931. hr = lpMailUser->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  4932. if (HR_FAILED(hr)) {
  4933. LUIOut(L3,"MailUser->SaveChanges FAILED");
  4934. retval=FALSE;
  4935. goto out;
  4936. }
  4937. else LUIOut(L3,"MailUser->SaveChanges PASSED, entry added to PAB/WAB");
  4938. //
  4939. // Call ResolveName on the entry we just added which will be an exact match,
  4940. // not display the UI and return a valid EID
  4941. //
  4942. // Allocate an AdrList for NumEntries of NumProps
  4943. NumEntries = 1; // How many AdrEntries
  4944. NumProps = 1; // How many props for each entry
  4945. if (!AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList)) {
  4946. LUIOut(L2, "Couldn't allocate AdrList. Test FAILED");
  4947. retval = FALSE;
  4948. goto out;
  4949. }
  4950. // Fill in the properties we want
  4951. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  4952. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszMatchDisplayName;
  4953. LUIOut(L2, "Calling IAdrBook->ResolveName with an exact match. Expect no UI and success.");
  4954. MessageBox(NULL, "Calling IAB->ResolveName on the entry that was just added. Since this will be an exact match, you should not see the resolve dialog box.",
  4955. "WAB Test Harness", MB_OK);
  4956. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  4957. hr = lpAdrBook->ResolveName((ULONG)glblhwnd,
  4958. MAPI_DIALOG, // ulFlags
  4959. lpTitleText,
  4960. lpAdrList);
  4961. if (HR_FAILED(hr)) {
  4962. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  4963. if (hr == MAPI_E_AMBIGUOUS_RECIP)
  4964. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  4965. else if (hr == MAPI_E_NOT_FOUND)
  4966. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  4967. else if (hr == MAPI_E_USER_CANCEL)
  4968. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  4969. else
  4970. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  4971. retval=FALSE;
  4972. goto out;
  4973. }
  4974. else LUIOut(L3,"IAdrBook->ResolveName call PASSED");
  4975. if (MessageBox(NULL, "Did you see the ResolveName dialog box appear?",
  4976. "WAB Test Harness", MB_YESNO) == IDYES) {
  4977. LUIOut(L3, "IABResolveName dialog displayed even tho we had an exact match. Test FAILED");
  4978. retval = FALSE;
  4979. goto out;
  4980. }
  4981. // Search through returned AdrList and verify each entry is resolved correctly
  4982. if (!VerifyResolvedAdrList(lpAdrList, NULL)) retval = FALSE;
  4983. // Store EID for multiple entry test case later on which needs a valid EID
  4984. //lpLookupEID = (ENTRYID*)lpAdrList->aEntries[0].rgPropVals[idx].Value.bin.lpb;
  4985. //cbLookupEID = lpAdrList->aEntries[0].rgPropVals[idx].Value.bin.cb;
  4986. lpLookupEID = (ENTRYID*)NULL;
  4987. cbLookupEID = 0;
  4988. // Cleanup
  4989. FreeAdrList(lpWABObject, &lpAdrList);
  4990. //
  4991. // Call ResolveName on a OneOff Address which should succede with
  4992. // no UI and return a valid EID. One off has a foo@com type DN and no email address
  4993. //
  4994. // Allocate an AdrList for NumEntries of NumProps
  4995. NumEntries = 1; // How many AdrEntries
  4996. NumProps = 1; // How many props for each entry
  4997. if (!AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList)) {
  4998. LUIOut(L2, "Couldn't allocate AdrList. Test FAILED");
  4999. retval = FALSE;
  5000. goto out;
  5001. }
  5002. // Fill in the properties we want
  5003. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5004. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszOneOff;
  5005. LUIOut(L2, "Calling IAdrBook->ResolveName with a one-off address (DN = foo@com type and no email addr). Expect no UI and success.");
  5006. MessageBox(NULL, "Calling IAB->ResolveName on a one-off address. Since this will be an exact match, you should not see the resolve dialog box.",
  5007. "WAB Test Harness", MB_OK);
  5008. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  5009. hr = lpAdrBook->ResolveName((ULONG)glblhwnd,
  5010. MAPI_DIALOG, // ulFlags
  5011. lpTitleText,
  5012. lpAdrList);
  5013. if (HR_FAILED(hr)) {
  5014. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5015. if (hr == MAPI_E_AMBIGUOUS_RECIP)
  5016. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  5017. else if (hr == MAPI_E_NOT_FOUND)
  5018. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  5019. else if (hr == MAPI_E_USER_CANCEL)
  5020. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  5021. else
  5022. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  5023. retval=FALSE;
  5024. goto out;
  5025. }
  5026. else LUIOut(L3,"IAdrBook->ResolveName call PASSED");
  5027. if (MessageBox(NULL, "Did you see the ResolveName dialog box appear?",
  5028. "WAB Test Harness", MB_YESNO) == IDYES) {
  5029. LUIOut(L3, "IABResolveName dialog displayed even tho we had an exact match. Test FAILED");
  5030. retval = FALSE;
  5031. goto out;
  5032. }
  5033. if (!VerifyResolvedAdrList(lpAdrList, NULL)) retval = FALSE;
  5034. FreeAdrList(lpWABObject, &lpAdrList);
  5035. //
  5036. // Call ResolveName on a OneOff Address which should succede with
  5037. // no UI and return a valid EID. One off has a DN of foo and an email address
  5038. // of type foo@com
  5039. //
  5040. // Allocate an AdrList for NumEntries of NumProps
  5041. NumEntries = 1; // How many AdrEntries
  5042. NumProps = 2; // How many props for each entry
  5043. if (!AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList)) {
  5044. LUIOut(L2, "Couldn't allocate AdrList. Test FAILED");
  5045. retval = FALSE;
  5046. goto out;
  5047. }
  5048. // Fill in the properties we want
  5049. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5050. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszOneOff2DisplayName;
  5051. lpAdrList->aEntries[0].rgPropVals[1].ulPropTag = PR_EMAIL_ADDRESS;
  5052. lpAdrList->aEntries[0].rgPropVals[1].Value.LPSZ = lpszOneOff2EmailAddress;
  5053. LUIOut(L2, "Calling IAdrBook->ResolveName with a one-off address (DN = foo, email addr = foo@...). Expect no UI and success.");
  5054. MessageBox(NULL, "Calling IAB->ResolveName on a second type of one-off address (DN = foo, EMail = foo@com type). Since this will be an exact match, you should not see the resolve dialog box.",
  5055. "WAB Test Harness", MB_OK);
  5056. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  5057. hr = lpAdrBook->ResolveName((ULONG)glblhwnd,
  5058. MAPI_DIALOG, // ulFlags
  5059. lpTitleText,
  5060. lpAdrList);
  5061. if (HR_FAILED(hr)) {
  5062. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5063. if (hr == MAPI_E_AMBIGUOUS_RECIP)
  5064. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  5065. else if (hr == MAPI_E_NOT_FOUND)
  5066. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  5067. else if (hr == MAPI_E_USER_CANCEL)
  5068. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  5069. else
  5070. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  5071. retval=FALSE;
  5072. goto out;
  5073. }
  5074. else LUIOut(L3,"IAdrBook->ResolveName call PASSED");
  5075. if (MessageBox(NULL, "Did you see the ResolveName dialog box appear?",
  5076. "WAB Test Harness", MB_YESNO) == IDYES) {
  5077. LUIOut(L3, "IABResolveName dialog displayed even tho we had an exact match. Test FAILED");
  5078. retval = FALSE;
  5079. goto out;
  5080. }
  5081. if (!VerifyResolvedAdrList(lpAdrList, NULL)) retval = FALSE;
  5082. FreeAdrList(lpWABObject, &lpAdrList);
  5083. //
  5084. // Call ResolveName on an entry we don't expect to match exactly
  5085. // Should bring up the resolve UI. Have the user select an entry and
  5086. // then check for success
  5087. //
  5088. // Allocate an AdrList for NumEntries of NumProps
  5089. NumEntries = 1; // How many AdrEntries
  5090. NumProps = 1; // How many props for each entry
  5091. if (!AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList)) {
  5092. LUIOut(L2, "Couldn't allocate AdrList. Test FAILED");
  5093. retval = FALSE;
  5094. goto out;
  5095. }
  5096. // Fill in the properties we want
  5097. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5098. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszNoMatch;
  5099. LUIOut(L2, "Calling IAdrBook->ResolveName with a non-exact match. Expect to see UI and success (user presses OK).");
  5100. MessageBox(NULL, "Calling IAB->ResolveName on 'No such name' which should not match. This should cause the resolve dialog box to display. Please select any entry from the ListBox and press the OK button",
  5101. "WAB Test Harness", MB_OK);
  5102. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  5103. hr = lpAdrBook->ResolveName((ULONG)glblhwnd,
  5104. MAPI_DIALOG, // ulFlags
  5105. lpTitleText,
  5106. lpAdrList);
  5107. if (HR_FAILED(hr)) {
  5108. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5109. if (hr == MAPI_E_AMBIGUOUS_RECIP)
  5110. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  5111. else if (hr == MAPI_E_NOT_FOUND)
  5112. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  5113. else if (hr == MAPI_E_USER_CANCEL)
  5114. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  5115. else
  5116. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  5117. retval=FALSE;
  5118. goto out;
  5119. }
  5120. else LUIOut(L3,"IAdrBook->ResolveName call PASSED");
  5121. if (MessageBox(NULL, "Did you see the ResolveName dialog box appear?",
  5122. "WAB Test Harness", MB_YESNO) == IDNO) {
  5123. LUIOut(L3, "IABResolveName dialog did not display even tho we did not have an exact match. Test FAILED");
  5124. retval = FALSE;
  5125. goto out;
  5126. }
  5127. if (!VerifyResolvedAdrList(lpAdrList, NULL)) retval = FALSE;
  5128. FreeAdrList(lpWABObject, &lpAdrList);
  5129. //
  5130. // Call ResolveName on an entry we don't expect to match exactly
  5131. // Should bring up the resolve UI. Have the user cancel from the UI
  5132. // then check for MAPI_E_USER_CANCEL
  5133. //
  5134. // Allocate an AdrList for NumEntries of NumProps
  5135. NumEntries = 1; // How many AdrEntries
  5136. NumProps = 1; // How many props for each entry
  5137. if (!AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList)) {
  5138. LUIOut(L2, "Couldn't allocate AdrList. Test FAILED");
  5139. retval = FALSE;
  5140. goto out;
  5141. }
  5142. // Fill in the properties we want
  5143. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5144. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszNoMatch;
  5145. LUIOut(L2, "Calling IAdrBook->ResolveName with a non-exact match. Expect to see UI and MAPI_E_USER_CANCEL (user presses CANCEL).");
  5146. MessageBox(NULL, "Calling IAB->ResolveName on 'No such name' which should not match. This should cause the resolve dialog box to display. When the ListBox is displayed, please press the CANCEL button",
  5147. "WAB Test Harness", MB_OK);
  5148. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  5149. hr = lpAdrBook->ResolveName(
  5150. (ULONG)glblhwnd,
  5151. MAPI_DIALOG, // ulFlags
  5152. lpTitleText,
  5153. lpAdrList);
  5154. if (hr == MAPI_E_USER_CANCEL) {
  5155. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  5156. LUIOut(L3,"IAdrBook->ResolveName call PASSED");
  5157. }
  5158. else if (hr == MAPI_E_AMBIGUOUS_RECIP) {
  5159. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  5160. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5161. retval=FALSE;
  5162. goto out;
  5163. }
  5164. else if (hr == MAPI_E_NOT_FOUND) {
  5165. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  5166. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5167. retval=FALSE;
  5168. goto out;
  5169. }
  5170. else {
  5171. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  5172. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5173. retval=FALSE;
  5174. goto out;
  5175. }
  5176. if (MessageBox(NULL, "Did you see the ResolveName dialog box appear?",
  5177. "WAB Test Harness", MB_YESNO) == IDNO) {
  5178. LUIOut(L3, "IABResolveName dialog did not display even tho we did not have an exact match. Test FAILED");
  5179. retval = FALSE;
  5180. goto out;
  5181. }
  5182. // Don't want to track the success of verify for this case
  5183. VerifyResolvedAdrList(lpAdrList, NULL);
  5184. FreeAdrList(lpWABObject, &lpAdrList);
  5185. //
  5186. // Call ResolveName on 4 entries as follows:
  5187. // * Entry with a non-zero EID prop -> already resolved so no UI
  5188. // * One-off entry with NULL EID -> will resolve but not bring up UI
  5189. // * non-exact match with NULL EID -> Will resolve and bring up UI
  5190. // * exact match with NULL EID -> Will resolve but not bring up UI
  5191. //
  5192. // When the UI is presented to the user, they should select a valid
  5193. // entry and press OK. VerifyAdrList is expected to succede.
  5194. //
  5195. // Allocate an AdrList for NumEntries of NumProps
  5196. NumEntries = 2; // How many AdrEntries
  5197. NumProps = 1; // How many props for each entry
  5198. if (!AllocateAdrList(lpWABObject, NumEntries, NumProps, &lpAdrList)) {
  5199. LUIOut(L2, "Couldn't allocate AdrList. Test FAILED");
  5200. retval = FALSE;
  5201. goto out;
  5202. }
  5203. // [ENTRY #1] - Exact match pre-resolve
  5204. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5205. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszMatchDisplayName;
  5206. // [ENTRY #2] - One-off pre-resolve
  5207. lpAdrList->aEntries[1].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5208. lpAdrList->aEntries[1].rgPropVals[0].Value.LPSZ = lpszOneOffDisplayName;
  5209. // Pre-resolve these entries
  5210. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  5211. hr = lpAdrBook->ResolveName((ULONG)glblhwnd,
  5212. (ULONG)0, // want no UI this time
  5213. lpTitleText,
  5214. lpAdrList);
  5215. if (HR_FAILED(hr)) {
  5216. LUIOut(L3,"PRE-RESOLVE FAILED: IAdrBook->ResolveName call FAILED");
  5217. if (hr == MAPI_E_AMBIGUOUS_RECIP)
  5218. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  5219. else if (hr == MAPI_E_NOT_FOUND)
  5220. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  5221. else if (hr == MAPI_E_USER_CANCEL)
  5222. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  5223. else
  5224. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  5225. retval=FALSE;
  5226. goto out;
  5227. }
  5228. // Allocate the final AdrList for NumEntries of NumProps
  5229. NumEntries = 5; // How many AdrEntries
  5230. NumProps = 2; // How many props for each new entry
  5231. if (!GrowAdrList(NumEntries, NumProps, &lpAdrList)) {
  5232. LUIOut(L2, "Couldn't grow AdrList. Test FAILED");
  5233. retval = FALSE;
  5234. goto out;
  5235. }
  5236. // [ENTRY #3] - Non-exact match not resolved
  5237. lpAdrList->aEntries[2].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5238. lpAdrList->aEntries[2].rgPropVals[0].Value.LPSZ = lpszNoMatch;
  5239. lpAdrList->aEntries[2].rgPropVals[1].ulPropTag = PR_NULL;
  5240. // [ENTRY #4] - Exact match not resolved
  5241. lpAdrList->aEntries[3].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5242. lpAdrList->aEntries[3].rgPropVals[0].Value.LPSZ = lpszMatchDisplayName;
  5243. lpAdrList->aEntries[3].rgPropVals[1].ulPropTag = PR_NULL;
  5244. // [ENTRY #5] - one-off type 2 (dispname and email addr) not resolved
  5245. // Fill in the properties we want
  5246. //PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  5247. //PropValue[1].ulPropTag = PR_ADDRTYPE;
  5248. //PropValue[2].ulPropTag = PR_EMAIL_ADDRESS;
  5249. lpAdrList->aEntries[4].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5250. lpAdrList->aEntries[4].rgPropVals[0].Value.LPSZ = lpszOneOff2DisplayName;
  5251. lpAdrList->aEntries[4].rgPropVals[1].ulPropTag = PR_EMAIL_ADDRESS;
  5252. lpAdrList->aEntries[4].rgPropVals[1].Value.LPSZ = lpszOneOff2EmailAddress;
  5253. LUIOut(L2, "Calling IAdrBook->ResolveName with 5 Entries. Expect to see UI once and success (user presses OK).");
  5254. MessageBox(NULL, "Calling IAB->ResolveName with multiple entries. This should cause the resolve dialog box to display only once. Please select any entry from the ListBox and press the OK button",
  5255. "WAB Test Harness", MB_OK);
  5256. strcpy(lpTitleText, "IAdrBook->ResolveName Test");
  5257. hr = lpAdrBook->ResolveName((ULONG)glblhwnd,
  5258. MAPI_DIALOG, // ulFlags
  5259. lpTitleText,
  5260. lpAdrList);
  5261. if (HR_FAILED(hr)) {
  5262. LUIOut(L3,"IAdrBook->ResolveName call FAILED");
  5263. if (hr == MAPI_E_AMBIGUOUS_RECIP)
  5264. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_AMBIGUOUS_RECIP");
  5265. else if (hr == MAPI_E_NOT_FOUND)
  5266. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_NOT_FOUND");
  5267. else if (hr == MAPI_E_USER_CANCEL)
  5268. LUIOut(L3, "IAdrBook->ResolveName returned MAPI_E_USER_CANCEL");
  5269. else
  5270. LUIOut(L3, "IAdrBook->ResolveName returned UNKNOWN result code");
  5271. retval=FALSE;
  5272. goto out;
  5273. }
  5274. else LUIOut(L3,"IAdrBook->ResolveName call PASSED");
  5275. if (MessageBox(NULL, "Did you see the ResolveName dialog box appear?",
  5276. "WAB Test Harness", MB_YESNO) == IDNO) {
  5277. LUIOut(L3, "IABResolveName dialog did not display even tho we did not have an exact match. Test FAILED");
  5278. retval = FALSE;
  5279. goto out;
  5280. }
  5281. if (!VerifyResolvedAdrList(lpAdrList, NULL)) retval = FALSE;
  5282. // Now delete the entry from the wab
  5283. hr = lpMailUser->GetProps( IN (LPSPropTagArray) &SPTArrayEntryID,
  5284. IN 0, //Flags
  5285. OUT &cValues,
  5286. OUT &lpSPropValueEntryID);
  5287. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag, cValues))) {
  5288. LUIOut(L3,"GetProps FAILED for MailUser");
  5289. retval=FALSE;
  5290. goto out;
  5291. }
  5292. hr = HrCreateEntryListFromID(lpWABObject,
  5293. IN lpSPropValueEntryID->Value.bin.cb,
  5294. IN (ENTRYID*)lpSPropValueEntryID->Value.bin.lpb,
  5295. OUT &lpEntryList);
  5296. if (HR_FAILED(hr)) {
  5297. LUIOut(L3,"Could not Create Entry List");
  5298. retval=FALSE;
  5299. goto out;
  5300. }
  5301. // Then pass the lpEntryList to DeleteEntries to delete ...
  5302. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  5303. if (HR_FAILED(hr)) {
  5304. LUIOut(L3,"Could not Delete Entry. DeleteEntry returned 0x%x", hr);
  5305. FreeEntryList(lpWABObject, &lpEntryList);
  5306. retval=FALSE;
  5307. goto out;
  5308. }
  5309. FreeEntryList(lpWABObject, &lpEntryList);
  5310. FreeAdrList(lpWABObject, &lpAdrList);
  5311. #ifdef DISTLIST
  5312. //
  5313. // Try to create a DL entry in the container
  5314. //
  5315. LUIOut(L2, "Creating a Distribution List in the container");
  5316. LUIOut(L3, "Calling GetProps on the container with the PR_DEF_CREATE_DL property");
  5317. // Need to get the template ID so we call GetProps with PR_DEF_CREATE_DL
  5318. hr = lpABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  5319. IN 0, //Flags
  5320. OUT &cValues,
  5321. OUT &lpSPropValueDL);
  5322. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  5323. LUIOut(L3,"GetProps failed for Default DL template");
  5324. retval=FALSE;
  5325. goto out;
  5326. }
  5327. // The returned value of PR_DEF_CREATE_DL is an
  5328. // EntryID which one can pass to CreateEntry
  5329. //
  5330. LUIOut(L3, "Calling IABContainer->CreateEntry with the EID from GetProps");
  5331. hr = lpABCont->CreateEntry( IN lpSPropValueDL->Value.bin.cb,
  5332. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb,
  5333. IN 0,
  5334. OUT (LPMAPIPROP *) &lpDistList);
  5335. if (HR_FAILED(hr)) {
  5336. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  5337. retval=FALSE;
  5338. goto out;
  5339. }
  5340. //
  5341. // Then set the properties
  5342. //
  5343. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  5344. cValues = 1; //# of props we are setting
  5345. lstrcpy((LPTSTR)EntProp[0], lpszInput2);
  5346. LUIOut(L2,"DistList Entry to Add: %s",EntProp[0]);
  5347. for (i=0; i<(int)cValues;i++)
  5348. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  5349. hr = lpDistList->SetProps(IN cValues,
  5350. IN PropValue,
  5351. IN NULL);
  5352. if (HR_FAILED(hr)) {
  5353. LUIOut(L3,"DistList->SetProps call FAILED for %s properties",PropValue[0].Value.LPSZ);
  5354. retval=FALSE;
  5355. goto out;
  5356. }
  5357. else LUIOut(L3,"DistList->SetProps call PASSED for %s properties",PropValue[0].Value.LPSZ);
  5358. hr = lpDistList->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  5359. if (HR_FAILED(hr)) {
  5360. LUIOut(L3,"DistList->SaveChanges FAILED");
  5361. retval=FALSE;
  5362. goto out;
  5363. }
  5364. else LUIOut(L3,"DistList->SaveChanges PASSED, entry added to PAB/WAB");
  5365. //
  5366. // Do a ResolveNames on the string
  5367. //
  5368. LUIOut(L2, "Retrieving the entry and verifying against what we tried to save.");
  5369. // use WAB Allocators here
  5370. #ifdef PAB
  5371. if (! (sc = MAPIAllocateBuffer(sizeof(ADRLIST) + sizeof(ADRENTRY), (void **)&lpAdrList))) {
  5372. #endif //PAB
  5373. #ifdef WAB
  5374. if (! (sc = lpWABObject->AllocateBuffer(sizeof(ADRLIST) + sizeof(ADRENTRY), (void **)&lpAdrList))) {
  5375. #endif //WAB
  5376. lpAdrList->cEntries = 1;
  5377. lpAdrList->aEntries[0].ulReserved1 = 0;
  5378. lpAdrList->aEntries[0].cValues = 1;
  5379. #ifdef PAB
  5380. if (! (sc = MAPIAllocateMore(sizeof(SPropValue), lpAdrList,
  5381. (void **)&lpAdrList->aEntries[0].rgPropVals))) {
  5382. #endif //WAB
  5383. #ifdef WAB
  5384. if (! (sc = lpWABObject->AllocateMore(sizeof(SPropValue), lpAdrList,
  5385. (void **)&lpAdrList->aEntries[0].rgPropVals))) {
  5386. #endif //WAB
  5387. lpAdrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
  5388. lpAdrList->aEntries[0].rgPropVals[0].Value.LPSZ = lpszInput2;
  5389. lpFlagList->cFlags = 1;
  5390. lpFlagList->ulFlag[0] = MAPI_UNRESOLVED;
  5391. hr = lpABCont->ResolveNames(
  5392. (LPSPropTagArray)&SPTArrayCols, // tag set for disp_name and eid
  5393. 0, // ulFlags
  5394. lpAdrList,
  5395. lpFlagList);
  5396. if (HR_FAILED(hr)) {
  5397. LUIOut(L3,"ABContainer->ResolveNames call FAILED, returned 0x%x", hr);
  5398. retval=FALSE;
  5399. goto out;
  5400. }
  5401. else LUIOut(L3,"ABContainer->ResolveNames call PASSED");
  5402. Found = FALSE;
  5403. // Search through returned AdrList for our entry
  5404. for(i=0; ((i<(int) lpAdrList->cEntries) && (!Found)); ++i) {
  5405. cMaxProps = (int)lpAdrList->aEntries[i].cValues;
  5406. //Check to see if Display Name exists
  5407. idx=0;
  5408. while((lpAdrList->aEntries[i].rgPropVals[idx].ulPropTag != PR_DISPLAY_NAME )
  5409. && retval) {
  5410. idx++;
  5411. if(idx == cMaxProps) {
  5412. LUIOut(L4, "PR_DISPLAY_NAME was not found in the lpAdrList");
  5413. retval = FALSE;
  5414. }
  5415. }
  5416. LUIOut(L4,"Display Name: %s",lpAdrList->aEntries[i].rgPropVals[idx].Value.LPSZ);
  5417. if (!lstrcmp(lpAdrList->aEntries[i].rgPropVals[idx].Value.LPSZ,lpszInput2)) {
  5418. LUIOut(L3, "Found the entry we just added");
  5419. Found = TRUE;
  5420. }
  5421. //Check to see if EntryID exists
  5422. LUIOut(L3, "Verifying a PR_ENTRYID entry exists in the PropertyTagArray");
  5423. idx=0;
  5424. while((lpAdrList->aEntries[i].rgPropVals[idx].ulPropTag != PR_ENTRYID )
  5425. && retval) {
  5426. idx++;
  5427. if(idx == cMaxProps) {
  5428. LUIOut(L4, "PR_ENTRYID was not found in the lpAdrList");
  5429. retval = FALSE;
  5430. }
  5431. }
  5432. if (!Found) LUIOut(L3, "Did not find the entry. Test FAILED");
  5433. if (idx < cMaxProps) LUIOut(L3, "EntryID found");
  5434. if (!(retval && Found)) retval = FALSE;
  5435. else {
  5436. // Store EID for call to OpenEntry
  5437. }
  5438. }
  5439. }
  5440. #ifdef PAB
  5441. MAPIFreeBuffer(lpAdrList);
  5442. #endif //PAB
  5443. #ifdef WAB
  5444. lpWABObject->FreeBuffer(lpAdrList);
  5445. #endif //WAB
  5446. }
  5447. #endif //DISTLIST
  5448. out:
  5449. FreeAdrList(lpWABObject, &lpAdrList);
  5450. #ifdef PAB
  5451. if (lpEidPAB)
  5452. MAPIFreeBuffer(lpEidPAB);
  5453. if (lpSPropValueAddress)
  5454. MAPIFreeBuffer(lpSPropValueAddress);
  5455. if (lpSPropValueEntryID)
  5456. MAPIFreeBuffer(lpSPropValueEntryID);
  5457. if (lpSPropValueDL)
  5458. MAPIFreeBuffer(lpSPropValueDL);
  5459. #endif
  5460. #ifdef WAB
  5461. if (lpEidPAB)
  5462. lpWABObject->FreeBuffer(lpEidPAB);
  5463. if (lpSPropValueAddress)
  5464. lpWABObject->FreeBuffer(lpSPropValueAddress);
  5465. if (lpSPropValueEntryID)
  5466. lpWABObject->FreeBuffer(lpSPropValueEntryID);
  5467. if (lpSPropValueDL)
  5468. lpWABObject->FreeBuffer(lpSPropValueDL);
  5469. #endif
  5470. if (lpMailUser)
  5471. lpMailUser->Release();
  5472. if (lpDistList)
  5473. lpDistList->Release();
  5474. if (lpABCont)
  5475. lpABCont->Release();
  5476. if (lpDLCont)
  5477. lpDLCont->Release();
  5478. if (lpAdrBook)
  5479. lpAdrBook->Release();
  5480. #ifdef PAB
  5481. if (lpMAPISession)
  5482. lpMAPISession->Release();
  5483. MAPIUninitialize();
  5484. #endif
  5485. #ifdef WAB
  5486. if (lpWABObject)
  5487. lpWABObject->Release();
  5488. #endif
  5489. return retval;
  5490. }
  5491. BOOL PAB_IABNewEntry_Details()
  5492. {
  5493. LPADRBOOK lpAdrBook = NULL;
  5494. LPABCONT lpABCont= NULL;
  5495. ULONG cbEidPAB = 0, cbEid = 0;
  5496. LPENTRYID lpEidPAB = NULL, lpEid = NULL;
  5497. ULONG ulObjType=NULL;
  5498. HRESULT hr = hrSuccess;
  5499. int retval=TRUE;
  5500. ULONG UIParam = (ULONG)glblhwnd;
  5501. LUIOut(L1," ");
  5502. LUIOut(L1,"Running PAB_IABNewEntry//Details");
  5503. LUIOut(L2,"-> Verifies IAdrBook->NewEntry and Details are functional by performing the following:");
  5504. LUIOut(L2, " Calls NewEntry and then passes the returned EID to Details");
  5505. LUIOut(L1," ");
  5506. if (!GetAB(OUT &lpAdrBook)) {
  5507. retval = FALSE;
  5508. goto out;
  5509. }
  5510. // Call IAddrBook::OpenEntry to get the root container to PAB - MAPI
  5511. assert(lpAdrBook != NULL);
  5512. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  5513. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  5514. if (HR_FAILED(hr)) {
  5515. LUIOut(L2,"IAddrBook->OpenEntry Failed");
  5516. retval=FALSE;
  5517. goto out;
  5518. }
  5519. //
  5520. // Bringing up the NewEntry UI
  5521. //
  5522. LUIOut(L2, "Calling NewEntry");
  5523. assert(lpABCont != NULL);
  5524. MessageBox(NULL, "Calling IAB->NewEntry, which will bring up the property panes for creating a new WAB entry. Fill in as many fields as possible and press the OK button",
  5525. "WAB Test Harness", MB_OK);
  5526. hr = lpAdrBook->NewEntry(
  5527. IN (ULONG)glblhwnd,
  5528. IN 0, //ulFlags - reserved, must be zero
  5529. IN cbEidPAB,
  5530. IN lpEidPAB,
  5531. IN 0, //cbEIDNewEntryTpl - not supported by WAB, must be zero
  5532. IN NULL, //lpEIDNewEntryTpl - not supported by WAB, must be zero
  5533. OUT &cbEid,
  5534. OUT &lpEid);
  5535. if (HR_FAILED(hr)) {
  5536. LUIOut(L2,"IAddrBook->NewEntry Failed");
  5537. retval=FALSE;
  5538. goto out;
  5539. }
  5540. MessageBox(NULL, "Calling IAB->Details, which will bring up the property panes for the WAB entry you just created. Please verify the values of the fields are as expected and press the OK button",
  5541. "WAB Test Harness", MB_OK);
  5542. hr = lpAdrBook->Details(
  5543. &UIParam,
  5544. IN NULL, //lpfnDismiss - must be NULL for tier1 WAB
  5545. IN 0, //lpvDismissContext
  5546. IN cbEid,
  5547. IN lpEid,
  5548. IN NULL, //lpfButtonCallback - not supported in WAB, must be NULL
  5549. IN NULL, //lpvButtonContext - not supported in WAB, must be NULL
  5550. IN NULL, //lpszButtonText - not supported in WAB, must be NULL
  5551. IN 0); //ulFlags - not supported in WAB, must be zero
  5552. if (HR_FAILED(hr)) {
  5553. LUIOut(L2,"IAddrBook->Details Failed");
  5554. retval=FALSE;
  5555. goto out;
  5556. }
  5557. if (MessageBox(NULL, "Did the new entry get added/displayed properly?",
  5558. "WAB Test Harness", MB_YESNO) == IDNO) {
  5559. LUIOut(L3, "User ansered No to the pass-test message box. Test FAILED");
  5560. retval = FALSE;
  5561. goto out;
  5562. }
  5563. out:
  5564. #ifdef PAB
  5565. if (lpEid)
  5566. MAPIFreeBuffer(lpEid);
  5567. if (lpEidPAB)
  5568. MAPIFreeBuffer(lpEidPAB);
  5569. #endif
  5570. #ifdef WAB
  5571. if (lpEid)
  5572. lpWABObject->FreeBuffer(lpEid);
  5573. if (lpEidPAB)
  5574. lpWABObject->FreeBuffer(lpEidPAB);
  5575. #endif
  5576. if (lpABCont)
  5577. lpABCont->Release();
  5578. if (lpAdrBook)
  5579. lpAdrBook->Release();
  5580. #ifdef PAB
  5581. if (lpMAPISession)
  5582. lpMAPISession->Release();
  5583. MAPIUninitialize();
  5584. #endif
  5585. #ifdef WAB
  5586. if (lpWABObject)
  5587. lpWABObject->Release();
  5588. #endif
  5589. return(retval);
  5590. }
  5591. BOOL Performance()
  5592. {
  5593. HRESULT hr;
  5594. int retval=TRUE;
  5595. DWORD StartTime, StopTime, Elapsed;
  5596. LPVOID Reserved1 = NULL;
  5597. DWORD Reserved2 = 0;
  5598. LPADRBOOK lpLocalAdrBook;
  5599. LPABCONT lpABCont= NULL;
  5600. ULONG cbEidPAB = 0;
  5601. LPENTRYID lpEidPAB = NULL;
  5602. LPMAPITABLE lpTable = NULL;
  5603. LPSRowSet lpRows = NULL;
  5604. LPWABOBJECT lpLocalWABObject;
  5605. ENTRYLIST EntryList,*lpEntryList = &EntryList;
  5606. ULONG cValues = 0, ulObjType=NULL;
  5607. int i=0,k=0;
  5608. unsigned int NumEntries;
  5609. DWORD PerfData;
  5610. WAB_PARAM WP;
  5611. LUIOut(L1, "WAB Performance Suite");
  5612. NumEntries = 20;
  5613. LUIOut(L1, " ");
  5614. LUIOut(L2, "Running performance data for %u entries.", NumEntries);
  5615. DeleteWABFile();
  5616. CreateMultipleEntries(NumEntries,&PerfData);
  5617. LUIOut(L2, "** Time for SaveChanges (Avg. per entry) = %u milliseconds", PerfData);
  5618. hr = WABOpen(&lpLocalAdrBook, &lpLocalWABObject, &WP, Reserved2);
  5619. if (HR_FAILED(hr)) {
  5620. LUIOut(L2,"WABOpen Failed");
  5621. retval=FALSE;
  5622. goto out;
  5623. }
  5624. assert(lpLocalAdrBook != NULL);
  5625. hr = OpenPABID( IN lpLocalAdrBook, OUT &cbEidPAB,
  5626. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  5627. if (HR_FAILED(hr)) {
  5628. LUIOut(L2,"OpenPABID Failed");
  5629. retval=FALSE;
  5630. goto out;
  5631. }
  5632. StartTime = GetTickCount();
  5633. hr = lpABCont->GetContentsTable(ULONG(0), &lpTable);
  5634. StopTime = GetTickCount();
  5635. if (HR_FAILED(hr)) {
  5636. LUIOut(L3,"ABContainer->GetContentsTable call FAILED, returned 0x%x", hr);
  5637. retval=FALSE;
  5638. goto out;
  5639. }
  5640. Elapsed = StopTime-StartTime;
  5641. LUIOut(L2, "** Time to GetContentsTable (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5642. hr = lpTable->QueryRows(LONG(0x7FFFFFFF),
  5643. ULONG(0),
  5644. &lpRows);
  5645. if (HR_FAILED(hr)) {
  5646. LUIOut(L3,"Table->QueryRows call FAILED with errorcode 0x%x", hr);
  5647. retval=FALSE;
  5648. goto out;
  5649. }
  5650. if (!lpRows->cRows) {
  5651. LUIOut(L2, "QueryRows did not find any entries. Test FAILED");
  5652. retval=FALSE;
  5653. goto out;
  5654. }
  5655. else
  5656. LUIOut(L3, "QueryRows returned %u rows.", lpRows->cRows);
  5657. // Change the EntryIDs to a LPENTRYLIST
  5658. hr = HrCreateEntryListFromRows(IN lpLocalWABObject,
  5659. IN &lpRows,
  5660. OUT (ENTRYLIST**)&lpEntryList);
  5661. if (HR_FAILED(hr)) {
  5662. LUIOut(L3,"Could not Create Entry List");
  5663. retval=FALSE;
  5664. goto out;
  5665. }
  5666. // Then pass the lpEntryList to DeleteEntries to delete ...
  5667. StartTime = GetTickCount();
  5668. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  5669. StopTime = GetTickCount();
  5670. Elapsed = StopTime-StartTime;
  5671. LUIOut(L2, "** Time to DeleteEntries (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5672. if (HR_FAILED(hr)) {
  5673. LUIOut(L3,"Could not Delete Entries. DeleteEntry returned 0x%x", hr);
  5674. FreeEntryList(lpLocalWABObject, &lpEntryList);
  5675. retval=FALSE;
  5676. goto out;
  5677. }
  5678. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  5679. FreeEntryList(lpLocalWABObject, (ENTRYLIST**)&lpEntryList);
  5680. if (lpTable) {
  5681. lpTable->Release();
  5682. lpTable = NULL;
  5683. }
  5684. lpLocalWABObject->FreeBuffer(lpEidPAB);
  5685. lpEidPAB = NULL;
  5686. lpABCont->Release();
  5687. lpABCont = NULL;
  5688. lpLocalAdrBook->Release();
  5689. lpLocalAdrBook = NULL;
  5690. lpLocalWABObject->Release();
  5691. lpLocalWABObject = NULL;
  5692. NumEntries = 100;
  5693. LUIOut(L1, " ");
  5694. LUIOut(L2, "Running performance data for %u entries.", NumEntries);
  5695. DeleteWABFile();
  5696. CreateMultipleEntries(NumEntries,&PerfData);
  5697. LUIOut(L2, "** Time for SaveChanges (Avg. per entry) = %u milliseconds", PerfData);
  5698. hr = WABOpen(&lpLocalAdrBook, &lpLocalWABObject, &WP, Reserved2);
  5699. if (HR_FAILED(hr)) {
  5700. LUIOut(L2,"WABOpen Failed");
  5701. retval=FALSE;
  5702. goto out;
  5703. }
  5704. assert(lpLocalAdrBook != NULL);
  5705. hr = OpenPABID( IN lpLocalAdrBook, OUT &cbEidPAB,
  5706. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  5707. if (HR_FAILED(hr)) {
  5708. LUIOut(L2,"OpenPABID Failed");
  5709. retval=FALSE;
  5710. goto out;
  5711. }
  5712. StartTime = GetTickCount();
  5713. hr = lpABCont->GetContentsTable(ULONG(0), &lpTable);
  5714. StopTime = GetTickCount();
  5715. if (HR_FAILED(hr)) {
  5716. LUIOut(L3,"ABContainer->GetContentsTable call FAILED, returned 0x%x", hr);
  5717. retval=FALSE;
  5718. goto out;
  5719. }
  5720. Elapsed = StopTime-StartTime;
  5721. LUIOut(L2, "** Time to GetContentsTable (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5722. hr = lpTable->QueryRows(LONG(0x7FFFFFFF),
  5723. ULONG(0),
  5724. &lpRows);
  5725. if (HR_FAILED(hr)) {
  5726. LUIOut(L3,"Table->QueryRows call FAILED with errorcode 0x%x", hr);
  5727. retval=FALSE;
  5728. goto out;
  5729. }
  5730. if (!lpRows->cRows) {
  5731. LUIOut(L2, "QueryRows did not find any entries. Test FAILED");
  5732. retval=FALSE;
  5733. goto out;
  5734. }
  5735. else
  5736. LUIOut(L3, "QueryRows returned %u rows.", lpRows->cRows);
  5737. // Change the EntryIDs to a LPENTRYLIST
  5738. hr = HrCreateEntryListFromRows(IN lpLocalWABObject,
  5739. IN &lpRows,
  5740. OUT (ENTRYLIST**)&lpEntryList);
  5741. if (HR_FAILED(hr)) {
  5742. LUIOut(L3,"Could not Create Entry List");
  5743. retval=FALSE;
  5744. goto out;
  5745. }
  5746. // Then pass the lpEntryList to DeleteEntries to delete ...
  5747. StartTime = GetTickCount();
  5748. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  5749. StopTime = GetTickCount();
  5750. Elapsed = StopTime-StartTime;
  5751. LUIOut(L2, "** Time to DeleteEntries (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5752. if (HR_FAILED(hr)) {
  5753. LUIOut(L3,"Could not Delete Entries. DeleteEntry returned 0x%x", hr);
  5754. FreeEntryList(lpLocalWABObject, &lpEntryList);
  5755. retval=FALSE;
  5756. goto out;
  5757. }
  5758. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  5759. FreeEntryList(lpLocalWABObject, (ENTRYLIST**)&lpEntryList);
  5760. if (lpTable) {
  5761. lpTable->Release();
  5762. lpTable = NULL;
  5763. }
  5764. lpLocalWABObject->FreeBuffer(lpEidPAB);
  5765. lpEidPAB = NULL;
  5766. lpABCont->Release();
  5767. lpABCont = NULL;
  5768. lpLocalAdrBook->Release();
  5769. lpLocalAdrBook = NULL;
  5770. lpLocalWABObject->Release();
  5771. lpLocalWABObject = NULL;
  5772. NumEntries = 500;
  5773. LUIOut(L1, " ");
  5774. LUIOut(L2, "Running performance data for %u entries.", NumEntries);
  5775. DeleteWABFile();
  5776. CreateMultipleEntries(NumEntries,&PerfData);
  5777. LUIOut(L2, "** Time for SaveChanges (Avg. per entry) = %u milliseconds", PerfData);
  5778. hr = WABOpen(&lpLocalAdrBook, &lpLocalWABObject, &WP, Reserved2);
  5779. if (HR_FAILED(hr)) {
  5780. LUIOut(L2,"WABOpen Failed");
  5781. retval=FALSE;
  5782. goto out;
  5783. }
  5784. assert(lpLocalAdrBook != NULL);
  5785. hr = OpenPABID( IN lpLocalAdrBook, OUT &cbEidPAB,
  5786. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  5787. if (HR_FAILED(hr)) {
  5788. LUIOut(L2,"OpenPABID Failed");
  5789. retval=FALSE;
  5790. goto out;
  5791. }
  5792. StartTime = GetTickCount();
  5793. hr = lpABCont->GetContentsTable(ULONG(0), &lpTable);
  5794. StopTime = GetTickCount();
  5795. if (HR_FAILED(hr)) {
  5796. LUIOut(L3,"ABContainer->GetContentsTable call FAILED, returned 0x%x", hr);
  5797. retval=FALSE;
  5798. goto out;
  5799. }
  5800. Elapsed = StopTime-StartTime;
  5801. LUIOut(L2, "** Time to GetContentsTable (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5802. hr = lpTable->QueryRows(LONG(0x7FFFFFFF),
  5803. ULONG(0),
  5804. &lpRows);
  5805. if (HR_FAILED(hr)) {
  5806. LUIOut(L3,"Table->QueryRows call FAILED with errorcode 0x%x", hr);
  5807. retval=FALSE;
  5808. goto out;
  5809. }
  5810. if (!lpRows->cRows) {
  5811. LUIOut(L2, "QueryRows did not find any entries. Test FAILED");
  5812. retval=FALSE;
  5813. goto out;
  5814. }
  5815. else
  5816. LUIOut(L3, "QueryRows returned %u rows.", lpRows->cRows);
  5817. // Change the EntryIDs to a LPENTRYLIST
  5818. hr = HrCreateEntryListFromRows(IN lpLocalWABObject,
  5819. IN &lpRows,
  5820. OUT (ENTRYLIST**)&lpEntryList);
  5821. if (HR_FAILED(hr)) {
  5822. LUIOut(L3,"Could not Create Entry List");
  5823. retval=FALSE;
  5824. goto out;
  5825. }
  5826. // Then pass the lpEntryList to DeleteEntries to delete ...
  5827. StartTime = GetTickCount();
  5828. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  5829. StopTime = GetTickCount();
  5830. Elapsed = StopTime-StartTime;
  5831. LUIOut(L2, "** Time to DeleteEntries (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5832. if (HR_FAILED(hr)) {
  5833. LUIOut(L3,"Could not Delete Entries. DeleteEntry returned 0x%x", hr);
  5834. FreeEntryList(lpLocalWABObject, &lpEntryList);
  5835. retval=FALSE;
  5836. goto out;
  5837. }
  5838. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  5839. FreeEntryList(lpLocalWABObject, (ENTRYLIST**)&lpEntryList);
  5840. if (lpTable) {
  5841. lpTable->Release();
  5842. lpTable = NULL;
  5843. }
  5844. lpLocalWABObject->FreeBuffer(lpEidPAB);
  5845. lpEidPAB = NULL;
  5846. lpABCont->Release();
  5847. lpABCont = NULL;
  5848. lpLocalAdrBook->Release();
  5849. lpLocalAdrBook = NULL;
  5850. lpLocalWABObject->Release();
  5851. lpLocalWABObject = NULL;
  5852. NumEntries = 1000;
  5853. LUIOut(L1, " ");
  5854. LUIOut(L2, "Running performance data for %u entries.", NumEntries);
  5855. DeleteWABFile();
  5856. CreateMultipleEntries(NumEntries,&PerfData);
  5857. LUIOut(L2, "** Time for SaveChanges (Avg. per entry) = %u milliseconds", PerfData);
  5858. hr = WABOpen(&lpLocalAdrBook, &lpLocalWABObject, &WP, Reserved2);
  5859. if (HR_FAILED(hr)) {
  5860. LUIOut(L2,"WABOpen Failed");
  5861. retval=FALSE;
  5862. goto out;
  5863. }
  5864. assert(lpLocalAdrBook != NULL);
  5865. hr = OpenPABID( IN lpLocalAdrBook, OUT &cbEidPAB,
  5866. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  5867. if (HR_FAILED(hr)) {
  5868. LUIOut(L2,"OpenPABID Failed");
  5869. retval=FALSE;
  5870. goto out;
  5871. }
  5872. StartTime = GetTickCount();
  5873. hr = lpABCont->GetContentsTable(ULONG(0), &lpTable);
  5874. StopTime = GetTickCount();
  5875. if (HR_FAILED(hr)) {
  5876. LUIOut(L3,"ABContainer->GetContentsTable call FAILED, returned 0x%x", hr);
  5877. retval=FALSE;
  5878. goto out;
  5879. }
  5880. Elapsed = StopTime-StartTime;
  5881. LUIOut(L2, "** Time to GetContentsTable (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5882. hr = lpTable->QueryRows(LONG(0x7FFFFFFF),
  5883. ULONG(0),
  5884. &lpRows);
  5885. if (HR_FAILED(hr)) {
  5886. LUIOut(L3,"Table->QueryRows call FAILED with errorcode 0x%x", hr);
  5887. retval=FALSE;
  5888. goto out;
  5889. }
  5890. if (!lpRows->cRows) {
  5891. LUIOut(L2, "QueryRows did not find any entries. Test FAILED");
  5892. retval=FALSE;
  5893. goto out;
  5894. }
  5895. else
  5896. LUIOut(L3, "QueryRows returned %u rows.", lpRows->cRows);
  5897. // Change the EntryIDs to a LPENTRYLIST
  5898. hr = HrCreateEntryListFromRows(IN lpLocalWABObject,
  5899. IN &lpRows,
  5900. OUT (ENTRYLIST**)&lpEntryList);
  5901. if (HR_FAILED(hr)) {
  5902. LUIOut(L3,"Could not Create Entry List");
  5903. retval=FALSE;
  5904. goto out;
  5905. }
  5906. // Then pass the lpEntryList to DeleteEntries to delete ...
  5907. StartTime = GetTickCount();
  5908. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  5909. StopTime = GetTickCount();
  5910. Elapsed = StopTime-StartTime;
  5911. LUIOut(L2, "** Time to DeleteEntries (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5912. if (HR_FAILED(hr)) {
  5913. LUIOut(L3,"Could not Delete Entries. DeleteEntry returned 0x%x", hr);
  5914. FreeEntryList(lpLocalWABObject, &lpEntryList);
  5915. retval=FALSE;
  5916. goto out;
  5917. }
  5918. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  5919. FreeEntryList(lpLocalWABObject, (ENTRYLIST**)&lpEntryList);
  5920. if (lpTable) {
  5921. lpTable->Release();
  5922. lpTable = NULL;
  5923. }
  5924. lpLocalWABObject->FreeBuffer(lpEidPAB);
  5925. lpEidPAB = NULL;
  5926. lpABCont->Release();
  5927. lpABCont = NULL;
  5928. lpLocalAdrBook->Release();
  5929. lpLocalAdrBook = NULL;
  5930. lpLocalWABObject->Release();
  5931. lpLocalWABObject = NULL;
  5932. NumEntries = 5000;
  5933. LUIOut(L1, " ");
  5934. LUIOut(L2, "Running performance data for %u entries.", NumEntries);
  5935. DeleteWABFile();
  5936. CreateMultipleEntries(NumEntries,&PerfData);
  5937. LUIOut(L2, "** Time for SaveChanges (Avg. per entry) = %u milliseconds", PerfData);
  5938. hr = WABOpen(&lpLocalAdrBook, &lpLocalWABObject, &WP, Reserved2);
  5939. if (HR_FAILED(hr)) {
  5940. LUIOut(L2,"WABOpen Failed");
  5941. retval=FALSE;
  5942. goto out;
  5943. }
  5944. assert(lpLocalAdrBook != NULL);
  5945. hr = OpenPABID( IN lpLocalAdrBook, OUT &cbEidPAB,
  5946. OUT &lpEidPAB,OUT &lpABCont, OUT &ulObjType);
  5947. if (HR_FAILED(hr)) {
  5948. LUIOut(L2,"OpenPABID Failed");
  5949. retval=FALSE;
  5950. goto out;
  5951. }
  5952. StartTime = GetTickCount();
  5953. hr = lpABCont->GetContentsTable(ULONG(0), &lpTable);
  5954. StopTime = GetTickCount();
  5955. if (HR_FAILED(hr)) {
  5956. LUIOut(L3,"ABContainer->GetContentsTable call FAILED, returned 0x%x", hr);
  5957. retval=FALSE;
  5958. goto out;
  5959. }
  5960. Elapsed = StopTime-StartTime;
  5961. LUIOut(L2, "** Time to GetContentsTable (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5962. hr = lpTable->QueryRows(LONG(0x7FFFFFFF),
  5963. ULONG(0),
  5964. &lpRows);
  5965. if (HR_FAILED(hr)) {
  5966. LUIOut(L3,"Table->QueryRows call FAILED with errorcode 0x%x", hr);
  5967. retval=FALSE;
  5968. goto out;
  5969. }
  5970. if (!lpRows->cRows) {
  5971. LUIOut(L2, "QueryRows did not find any entries. Test FAILED");
  5972. retval=FALSE;
  5973. goto out;
  5974. }
  5975. else
  5976. LUIOut(L3, "QueryRows returned %u rows.", lpRows->cRows);
  5977. // Change the EntryIDs to a LPENTRYLIST
  5978. hr = HrCreateEntryListFromRows(IN lpLocalWABObject,
  5979. IN &lpRows,
  5980. OUT (ENTRYLIST**)&lpEntryList);
  5981. if (HR_FAILED(hr)) {
  5982. LUIOut(L3,"Could not Create Entry List");
  5983. retval=FALSE;
  5984. goto out;
  5985. }
  5986. // Then pass the lpEntryList to DeleteEntries to delete ...
  5987. StartTime = GetTickCount();
  5988. hr = lpABCont->DeleteEntries(IN lpEntryList,IN 0);
  5989. StopTime = GetTickCount();
  5990. Elapsed = StopTime-StartTime;
  5991. LUIOut(L2, "** Time to DeleteEntries (Avg. per entry) = %u.%03u milliseconds", Elapsed/NumEntries, ((Elapsed*1000)/NumEntries)-((Elapsed/NumEntries)*1000));
  5992. if (HR_FAILED(hr)) {
  5993. LUIOut(L3,"Could not Delete Entries. DeleteEntry returned 0x%x", hr);
  5994. FreeEntryList(lpLocalWABObject, &lpEntryList);
  5995. retval=FALSE;
  5996. goto out;
  5997. }
  5998. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  5999. FreeEntryList(lpLocalWABObject, (ENTRYLIST**)&lpEntryList);
  6000. if (lpTable) {
  6001. lpTable->Release();
  6002. lpTable = NULL;
  6003. }
  6004. lpLocalWABObject->FreeBuffer(lpEidPAB);
  6005. lpEidPAB = NULL;
  6006. lpABCont->Release();
  6007. lpABCont = NULL;
  6008. lpLocalAdrBook->Release();
  6009. lpLocalAdrBook = NULL;
  6010. // Don't want to release the WABObject at this point since we'll need it to free memory below
  6011. // lpLocalWABObject->Release();
  6012. // lpLocalWABObject = NULL;
  6013. out:
  6014. FreeRows(lpLocalWABObject, &lpRows); // Cleanup from first call to queryrows
  6015. FreeEntryList(lpLocalWABObject, (ENTRYLIST**)&lpEntryList);
  6016. if (lpTable) {
  6017. lpTable->Release();
  6018. lpTable = NULL;
  6019. }
  6020. #ifdef PAB
  6021. if (lpEidPAB)
  6022. MAPIFreeBuffer(lpEidPAB);
  6023. #endif
  6024. #ifdef WAB
  6025. if (lpEidPAB)
  6026. lpLocalWABObject->FreeBuffer(lpEidPAB);
  6027. #endif
  6028. if (lpABCont)
  6029. lpABCont->Release();
  6030. if (lpLocalAdrBook)
  6031. lpLocalAdrBook->Release();
  6032. #ifdef PAB
  6033. if (lpMAPISession)
  6034. lpMAPISession->Release();
  6035. MAPIUninitialize();
  6036. #endif
  6037. #ifdef WAB
  6038. if (lpLocalWABObject) {
  6039. lpLocalWABObject->Release();
  6040. lpLocalWABObject = NULL;
  6041. }
  6042. if (lpWABObject) {
  6043. lpWABObject->Release();
  6044. lpWABObject = NULL;
  6045. }
  6046. #endif
  6047. return retval;
  6048. }
  6049. BOOL PabCreateEntry()
  6050. {
  6051. ULONG ulFlags = 0;
  6052. HRESULT hr = hrSuccess;
  6053. SCODE sc = SUCCESS_SUCCESS;
  6054. int retval=TRUE;
  6055. #ifdef PAB
  6056. LPMAPISESSION lpMAPISession = NULL;
  6057. LPADRBOOK lpAdrBook = NULL;
  6058. LPABCONT lpPABCont= NULL;
  6059. LPABCONT lpDLCont= NULL;
  6060. ULONG cbEidPAB = 0, cbDLEntryID = 0;
  6061. LPENTRYID lpEidPAB = NULL, lpDLEntryID= NULL;
  6062. LPENTRYLIST lpEntryList=NULL; // needed for copy entry to PDL
  6063. ULONG cbEid=0; // entry id of the entry being added
  6064. LPENTRYID lpEid=NULL;
  6065. char EntProp[10][BIG_BUF]; //MAX_PROP
  6066. ULONG cValues = 0, ulObjType=NULL;
  6067. ULONG cRows = 0;
  6068. ULONG iEntry = 0;
  6069. int cEntriesToAdd,i=0,k=0;
  6070. char szEntryTag[SML_BUF],szTagBuf[SML_BUF],EntryBuf[MAX_BUF];
  6071. char szDLTag[SML_BUF];
  6072. LPMAPITABLE lpContentsTable = NULL;
  6073. LPSRowSet lpRowSet = NULL;
  6074. LPMAILUSER lpAddress = NULL;
  6075. SPropValue PropValue[3] = {0}; // This value is 3 because we
  6076. // will be setting 3 properties:
  6077. // EmailAddress, DisplayName and
  6078. // AddressType.
  6079. SizedSPropTagArray(2, Cols) = { 2, {PR_OBJECT_TYPE, PR_ENTRYID } };
  6080. LPSPropValue lpSPropValueAddress = NULL;
  6081. LPSPropValue lpSPropValueEntryID = NULL;
  6082. LPSPropValue lpSPropValueDL = NULL;
  6083. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  6084. SizedSPropTagArray(1,SPTArrayDL) = {1, {PR_DEF_CREATE_DL} };
  6085. SizedSPropTagArray(1,SPTArrayEntryID) = {1, {PR_ENTRYID} };
  6086. LUIOut(L1," ");
  6087. LUIOut(L1,"Running CreateEntries");
  6088. LUIOut(L2,"-> Creates specified entries in PAB");
  6089. LUIOut(L2, " And also copies them into a Distribution List");
  6090. LUIOut(L1," ");
  6091. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  6092. LUIOut(L2,"MapiInitLogon Failed");
  6093. retval = FALSE;
  6094. goto out;
  6095. }
  6096. // Get the IAddrBook
  6097. hr = (lpMAPISession)->OpenAddressBook(
  6098. IN 0, //window handle
  6099. IN NULL, //Interface identifier
  6100. IN 0, //flags
  6101. OUT &lpAdrBook); //pointer to address book object
  6102. if (HR_FAILED(hr)) {
  6103. LUIOut(L2,"OpenAddressBook Failed");
  6104. LUIOut(L3,"Could not open address book for the profile");
  6105. retval=FALSE;
  6106. goto out;
  6107. }
  6108. // Create an Entry of type "Other Address" in PAB
  6109. // OpenPAB
  6110. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  6111. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType);
  6112. if (HR_FAILED(hr)) {
  6113. LUIOut(L2,"OpenPABID Failed");
  6114. LUIOut(L3,"Could not Open PAB");
  6115. retval=FALSE;
  6116. goto out;
  6117. }
  6118. // Create a PDL to fill
  6119. hr = lpPABCont->GetProps( IN (LPSPropTagArray) &SPTArrayDL,
  6120. IN 0, //Flags
  6121. OUT &cValues,
  6122. OUT &lpSPropValueDL);
  6123. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  6124. LUIOut(L3,"GetProps failed for Default DL template");
  6125. retval=FALSE;
  6126. goto out;
  6127. }
  6128. // The returned value of PR_DEF_CREATE_DL is an
  6129. // EntryID which one can pass to CreateEntry
  6130. //
  6131. hr = lpPABCont->CreateEntry(
  6132. IN lpSPropValueDL->Value.bin.cb, //Template cbEid
  6133. IN (LPENTRYID) lpSPropValueDL->Value.bin.lpb, //Template lpEid
  6134. IN 0,
  6135. OUT (LPMAPIPROP *) &lpAddress);
  6136. if (HR_FAILED(hr)) {
  6137. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_DL");
  6138. retval=FALSE;
  6139. goto out;
  6140. }
  6141. //
  6142. // Then set the properties
  6143. //
  6144. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  6145. cValues = 1; //# of props we are setting
  6146. lstrcpy(szDLTag,"Name1");
  6147. GetPrivateProfileString("CreatePDL",szDLTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  6148. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  6149. LUIOut(L2,"PDL Entry to Add: %s",EntProp[0]);
  6150. for (i=0; i<(int)cValues;i++)
  6151. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  6152. hr = lpAddress->SetProps(IN cValues,
  6153. IN PropValue,
  6154. IN NULL);
  6155. if (HR_FAILED(hr)) {
  6156. LUIOut(L3,"SetProps on failed for %s properties",PropValue[0].Value.LPSZ);
  6157. retval=FALSE;
  6158. goto out;
  6159. }
  6160. //else LUIOut(L3,"SetProps Passed for %s properties",PropValue[0].Value.LPSZ);
  6161. hr = lpAddress->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  6162. if (HR_FAILED(hr)) {
  6163. LUIOut(L3,"SaveChanges failed for SetProps");
  6164. retval=FALSE;
  6165. goto out;
  6166. }
  6167. else LUIOut(L3,"PDL Entry Added to PAB");
  6168. if (lpAddress) {
  6169. lpAddress->Release();
  6170. lpAddress = NULL;
  6171. }
  6172. //***
  6173. //Get the PAB table so we can extract the DL
  6174. hr = lpPABCont->GetContentsTable( IN 0, //Flags
  6175. OUT &lpContentsTable);
  6176. if (HR_FAILED(hr)) {
  6177. LUIOut(L3,"GetContentsTable: Failed");
  6178. retval = FALSE;
  6179. goto out;
  6180. }
  6181. // look for the first PDL that you can find
  6182. hr = lpContentsTable->SetColumns(IN (LPSPropTagArray) &Cols,
  6183. IN 0);
  6184. if (HR_FAILED(hr)) {
  6185. LUIOut(L3,"SetColumns Failed");
  6186. retval = FALSE;
  6187. goto out;
  6188. }
  6189. do
  6190. {
  6191. hr = lpContentsTable->QueryRows(IN 1,
  6192. IN 0,
  6193. OUT &lpRowSet);
  6194. if (HR_FAILED(hr)){
  6195. LUIOut(L3,"QueryRows Failed");
  6196. retval = FALSE;
  6197. goto out;
  6198. }
  6199. cRows = lpRowSet->cRows;
  6200. for (iEntry = 0; iEntry < cRows; iEntry++)
  6201. {
  6202. //
  6203. // For each entry, process it.
  6204. //
  6205. //lpSPropValue = lpRowSet->aRow[iEntry].lpProps;
  6206. if ((lpRowSet->aRow[iEntry].lpProps[0].ulPropTag == PR_OBJECT_TYPE) &&
  6207. (lpRowSet->aRow[iEntry].lpProps[0].Value.ul == MAPI_DISTLIST))
  6208. {
  6209. if (lpRowSet->aRow[iEntry].lpProps[1].ulPropTag == PR_ENTRYID)
  6210. {
  6211. cbDLEntryID = lpRowSet->aRow[iEntry].lpProps[1].Value.bin.cb;
  6212. if ( !MAPIAllocateBuffer(cbDLEntryID, (LPVOID *)&lpDLEntryID)) {
  6213. CopyMemory(lpDLEntryID, (LPENTRYID)lpRowSet->aRow[iEntry].lpProps[1].Value.bin.lpb, cbDLEntryID);
  6214. }
  6215. else {
  6216. LUIOut(L3,"MAPIAllocateBuffer Failed");
  6217. retval = FALSE;
  6218. }
  6219. break;
  6220. }
  6221. }
  6222. }
  6223. //
  6224. // done, clean up
  6225. //
  6226. if(lpRowSet) {
  6227. FreeProws(lpRowSet);
  6228. lpRowSet = NULL;
  6229. }
  6230. }while((0!=cRows)&& (0==(cbDLEntryID)));
  6231. if (cbDLEntryID == 0)
  6232. LUIOut(L3,"PDL does not exist");
  6233. hr = lpPABCont->OpenEntry(
  6234. IN cbDLEntryID,
  6235. IN lpDLEntryID,
  6236. IN NULL, //default interface
  6237. IN MAPI_BEST_ACCESS, //flags
  6238. OUT &ulObjType,
  6239. OUT (LPUNKNOWN *) &lpDLCont);
  6240. if (HR_FAILED(hr)) {
  6241. LUIOut(L2,"OpenEntry Failed");
  6242. retval=FALSE;
  6243. goto out;
  6244. }
  6245. //***
  6246. // Get Entry displayname, addresstype and (email)address from INI
  6247. cEntriesToAdd= GetPrivateProfileInt("CreateEntries","NumEntries",0,INIFILENAME);
  6248. for (k= 0; k<cEntriesToAdd; k++) {
  6249. lstrcpy((LPSTR)szEntryTag,"Address");
  6250. lstrcat(szEntryTag,_itoa(k+1,szTagBuf,10));
  6251. // Addresses are comma delimited and enclosed in quotes
  6252. GetPrivateProfileString("CreateEntries",szEntryTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  6253. // parse the buffer for properties: displayname, emailaddress and address type
  6254. // if no email address specified
  6255. // then user will enter
  6256. // else enter programatically
  6257. // else part implemented below
  6258. hr = lpPABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  6259. IN 0, //Flags
  6260. OUT &cValues,
  6261. OUT &lpSPropValueAddress);
  6262. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  6263. LUIOut(L3,"GetProps failed for Default template");
  6264. retval=FALSE;
  6265. goto out;
  6266. }
  6267. // The returned value of PR_DEF_CREATE_MAILUSER is an
  6268. // EntryID which one can pass to CreateEntry
  6269. //
  6270. hr = lpPABCont->CreateEntry(
  6271. IN lpSPropValueAddress->Value.bin.cb, //Template cbEid
  6272. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb, //Template lpEid
  6273. IN 0,
  6274. OUT (LPMAPIPROP *) &lpAddress);
  6275. if (HR_FAILED(hr)) {
  6276. LUIOut(L3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  6277. retval=FALSE;
  6278. goto out;
  6279. }
  6280. //
  6281. // Then set the properties
  6282. //
  6283. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  6284. PropValue[1].ulPropTag = PR_ADDRTYPE;
  6285. PropValue[2].ulPropTag = PR_EMAIL_ADDRESS;
  6286. cValues = 3; //# of props we are setting
  6287. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  6288. LUIOut(L2,"Entry to Add: %s",EntProp[0]);
  6289. for (i=0; i<(int)cValues;i++)
  6290. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  6291. hr = lpAddress->SetProps(IN cValues,
  6292. IN PropValue,
  6293. IN NULL);
  6294. if (HR_FAILED(hr)) {
  6295. LUIOut(L3,"SetProps failed for %s",PropValue[0].Value.LPSZ);
  6296. retval=FALSE;
  6297. goto out;
  6298. }
  6299. //else LUIOut(L3,"SetProps Passed for %s properties",PropValue[0].Value.LPSZ);
  6300. hr = lpAddress->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  6301. if (HR_FAILED(hr)) {
  6302. LUIOut(L3,"SaveChanges failed for SetProps");
  6303. retval=FALSE;
  6304. goto out;
  6305. }
  6306. else LUIOut(L3,"Entry Added to PAB");
  6307. /** */
  6308. // Now copy the entry to the default DL
  6309. // Get EntryID
  6310. hr = lpAddress->GetProps(
  6311. IN (LPSPropTagArray) &SPTArrayEntryID,
  6312. IN 0,
  6313. OUT &cValues,
  6314. OUT &lpSPropValueEntryID);
  6315. if ((HR_FAILED(hr))||(PropError(lpSPropValueEntryID->ulPropTag))) {
  6316. {
  6317. LUIOut( L2,"GetProps on entry in PAB failed" );
  6318. retval = FALSE;
  6319. goto out;
  6320. }
  6321. cbEid = lpSPropValueEntryID->Value.bin.cb;
  6322. if ( !MAPIAllocateBuffer(cbEid, (LPVOID *)&lpEid)) {
  6323. CopyMemory(lpEid, (VOID*)(LPENTRYID) lpSPropValueEntryID->Value.bin.lpb, cbEid);
  6324. } else {
  6325. LUIOut(L3,"MAPIAllocateBuffer Failed");
  6326. retval = FALSE;
  6327. }
  6328. /** */
  6329. // Now copy the entry to the default DL
  6330. hr = HrCreateEntryListFromID(lpLocalWABObject, lpLocalWABObject, IN cbEid,
  6331. IN lpEid,
  6332. OUT &lpEntryList);
  6333. if (HR_FAILED(hr)) {
  6334. LUIOut(L3,"Could not Create Entry List");
  6335. retval=FALSE;
  6336. goto out;
  6337. }
  6338. hr = lpDLCont->CopyEntries(IN lpEntryList,IN NULL, IN NULL, IN NULL);
  6339. if (HR_FAILED(hr)) {
  6340. LUIOut(L3,"Could not Copy Entry %s", EntProp[0]);
  6341. retval=FALSE;
  6342. goto out;
  6343. } else LUIOut(L3,"Copied Entry: %s to PDL", EntProp[0]);
  6344. /** */
  6345. if (lpSPropValueAddress)
  6346. MAPIFreeBuffer(lpSPropValueAddress);
  6347. if (lpSPropValueEntryID)
  6348. MAPIFreeBuffer(lpSPropValueEntryID);
  6349. if (lpAddress) {
  6350. lpAddress->Release();
  6351. lpAddress = NULL;
  6352. }
  6353. }
  6354. out:
  6355. if (lpSPropValueAddress)
  6356. MAPIFreeBuffer(lpSPropValueAddress);
  6357. if (lpSPropValueEntryID)
  6358. MAPIFreeBuffer(lpSPropValueEntryID);
  6359. if (lpSPropValueDL)
  6360. MAPIFreeBuffer(lpSPropValueDL);
  6361. if (lpEid)
  6362. MAPIFreeBuffer(lpEid);
  6363. if (lpAddress)
  6364. lpAddress->Release();
  6365. if (lpContentsTable)
  6366. lpContentsTable->Release();
  6367. if (lpPABCont)
  6368. lpPABCont->Release();
  6369. if (lpDLCont)
  6370. lpDLCont->Release();
  6371. if (lpEidPAB)
  6372. MAPIFreeBuffer(lpEidPAB);
  6373. if (lpAdrBook)
  6374. lpAdrBook->Release();
  6375. if (lpMAPISession)
  6376. lpMAPISession->Release();
  6377. MAPIUninitialize();
  6378. #endif
  6379. return retval;
  6380. }
  6381. BOOL PabDeleteEntry()
  6382. {
  6383. ULONG ulFlags = 0;
  6384. HRESULT hr = hrSuccess;
  6385. SCODE sc = SUCCESS_SUCCESS;
  6386. int retval=TRUE;
  6387. #ifdef PAB
  6388. LPMAPISESSION lpMAPISession = NULL;
  6389. LPADRBOOK lpAdrBook = NULL;
  6390. LPABCONT lpPABCont= NULL;
  6391. ULONG cbEidPAB = 0;
  6392. LPENTRYID lpEidPAB = NULL;
  6393. char szDispName[BIG_BUF];
  6394. ULONG cValues = 0;
  6395. int cEntriesToDelete,i=0,k=0;
  6396. char szEntryTag[SML_BUF],szTagBuf[SML_BUF];
  6397. ULONG cRows = 0;
  6398. ULONG iEntry = 0;
  6399. LPMAPITABLE lpContentsTable = NULL;
  6400. LPSRowSet lpRowSet = NULL;
  6401. SPropValue PropValue = {0};
  6402. LPSPropValue lpSPropValue = NULL;
  6403. SizedSPropTagArray(2, Cols) = { 2, {PR_DISPLAY_NAME, PR_ENTRYID } };
  6404. LPENTRYLIST lpEntryList=NULL;
  6405. ULONG cbEid=0;
  6406. LPENTRYID lpEid=NULL;
  6407. LPVOID *lpEid2=NULL;
  6408. LUIOut(L1," ");
  6409. LUIOut(L1,"Running DeleteEntries");
  6410. LUIOut(L2,"-> Deletes specified entries from the PAB");
  6411. LUIOut(L1," ");
  6412. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  6413. LUIOut(L2,"MapiInitLogon Failed");
  6414. retval = FALSE;
  6415. goto out;
  6416. }
  6417. // Get the IAddrBook
  6418. hr = (lpMAPISession)->OpenAddressBook(
  6419. IN 0, //window handle
  6420. IN NULL, //Interface identifier
  6421. IN 0, //flags
  6422. OUT &lpAdrBook); //pointer to address book object
  6423. if (HR_FAILED(hr)) {
  6424. LUIOut(L2,"OpenAddressBook Failed");
  6425. LUIOut(L3,"Could not open address book for the profile");
  6426. retval=FALSE;
  6427. goto out;
  6428. }
  6429. // OpenPAB
  6430. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  6431. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType);
  6432. if (HR_FAILED(hr)) {
  6433. LUIOut(L2,"OpenPABID Failed");
  6434. LUIOut(L3,"Could not Open PAB");
  6435. retval=FALSE;
  6436. goto out;
  6437. }
  6438. // Get Entry displayname from INI
  6439. cEntriesToDelete = GetPrivateProfileInt("DeleteEntries","NumEntries",0,INIFILENAME);
  6440. for (k= 0; k<cEntriesToDelete; k++) {
  6441. lstrcpy((LPSTR)szEntryTag,"Name");
  6442. lstrcat(szEntryTag,_itoa(k+1,szTagBuf,10));
  6443. GetPrivateProfileString("DeleteEntries",szEntryTag,"",szDispName,MAX_BUF,INIFILENAME);
  6444. if (szDispName[0]==0) continue;
  6445. LUIOut(L2,"Entry to Delete: %s",szDispName);
  6446. cbEid=0;
  6447. //
  6448. // Get the Contents Table for the PAB container
  6449. //
  6450. hr = lpPABCont->GetContentsTable( IN 0, //Flags
  6451. OUT &lpContentsTable);
  6452. if (HR_FAILED(hr)) {
  6453. LUIOut(L3,"GetContentsTable: Failed");
  6454. goto out;
  6455. }
  6456. //
  6457. // Only interested in 2 columns:
  6458. // PR_DISPLAY_NAME and PR_ENTRYID
  6459. //
  6460. hr = lpContentsTable->SetColumns(IN (LPSPropTagArray) &Cols,
  6461. IN 0);
  6462. if (HR_FAILED(hr)) {
  6463. LUIOut(L3,"SetColumns Failed");
  6464. retval = FALSE;
  6465. goto out;
  6466. }
  6467. //
  6468. // Since we don't know how many entries exist in the PAB,
  6469. // we will scan them 1000 at a time till we find the desired
  6470. // contact or reach the end of the table...
  6471. do
  6472. {
  6473. hr = lpContentsTable->QueryRows(IN 1000,
  6474. IN 0,
  6475. OUT &lpRowSet);
  6476. if (HR_FAILED(hr)){
  6477. LUIOut(L3,"QueryRows Failed");
  6478. retval = FALSE;
  6479. goto out;
  6480. }
  6481. cRows = lpRowSet->cRows;
  6482. for (iEntry = 0; iEntry < cRows; iEntry++)
  6483. {
  6484. //
  6485. // For each entry, process it.
  6486. //
  6487. lpSPropValue = lpRowSet->aRow[iEntry].lpProps;
  6488. if ( (lpSPropValue[0].ulPropTag == PR_DISPLAY_NAME) &&
  6489. (!lstrcmpi(lpSPropValue[0].Value.LPSZ, szDispName)) )
  6490. {
  6491. if (lpSPropValue[1].ulPropTag == PR_ENTRYID)
  6492. {
  6493. cbEid = lpSPropValue[1].Value.bin.cb;
  6494. lpEid = (LPENTRYID) lpSPropValue[1].Value.bin.lpb;
  6495. if ( !MAPIAllocateBuffer(cbEid, (LPVOID *)&lpEid2)) {
  6496. CopyMemory(lpEid2, lpEid, cbEid);
  6497. lpEid= (LPENTRYID)lpEid2;
  6498. }
  6499. else {
  6500. LUIOut(L3,"MAPIAllocateBuffer Failed");
  6501. retval = FALSE;
  6502. }
  6503. //lpEid = (LPENTRYID) lpSPropValue[1].Value.bin.lpb;
  6504. // if ( !MAPIAllocateBuffer(cbEid, (LPVOID*)lppEid))
  6505. // {
  6506. // CopyMemory(*lppEid, lpEid, *lpcbEid);
  6507. // }
  6508. break;
  6509. }
  6510. }
  6511. }
  6512. //
  6513. // done, clean up
  6514. //
  6515. if(lpRowSet) {
  6516. FreeProws(lpRowSet);
  6517. lpRowSet = NULL;
  6518. }
  6519. }while((0!=cRows)&& (0==(cbEid)));
  6520. if (cbEid == 0)
  6521. LUIOut(L3,"Entry does not exist");
  6522. else {
  6523. //
  6524. // Change the EntryID to a LPENTRYLIST
  6525. //
  6526. hr = HrCreateEntryListFromID(lpLocalWABObject, IN cbEid,
  6527. IN lpEid,
  6528. OUT &lpEntryList);
  6529. if (HR_FAILED(hr)) {
  6530. LUIOut(L3,"Could not Create Entry List");
  6531. retval=FALSE;
  6532. goto out;
  6533. }
  6534. //
  6535. // Then pass the lpEntryList to DeleteEntries to delete ...
  6536. //
  6537. hr = lpPABCont->DeleteEntries(IN lpEntryList,IN 0);
  6538. if (HR_FAILED(hr)) {
  6539. LUIOut(L3,"Could not Delete Entry %s", szDispName);
  6540. retval=FALSE;
  6541. goto out;
  6542. } else LUIOut(L3,"Deleted Entry: %s", szDispName);
  6543. }
  6544. }
  6545. out:
  6546. if (lpSPropValue)
  6547. MAPIFreeBuffer(lpSPropValue);
  6548. if (lpContentsTable)
  6549. lpContentsTable->Release();
  6550. if (lpEid)
  6551. MAPIFreeBuffer(lpEid);
  6552. if (lpPABCont)
  6553. lpPABCont->Release();
  6554. if (lpEidPAB)
  6555. MAPIFreeBuffer(lpEidPAB);
  6556. if (lpAdrBook)
  6557. lpAdrBook->Release();
  6558. if (lpMAPISession)
  6559. lpMAPISession->Release();
  6560. MAPIUninitialize();
  6561. #endif
  6562. return retval;
  6563. }
  6564. BOOL PabEnumerateAll()
  6565. {
  6566. HRESULT hr = hrSuccess;
  6567. SCODE sc = SUCCESS_SUCCESS;
  6568. int i = 0,j = 0,retval=TRUE, bDistList = FALSE;
  6569. #ifdef PAB
  6570. LPMAPISESSION lpMAPISession = NULL;
  6571. LPADRBOOK lpAdrBook = NULL;
  6572. LPABCONT lpPABCont= NULL, lpDLCont = NULL;
  6573. ULONG ulEntries=0, ulEntriesDL = 0;
  6574. ULONG cbEid=0, cbDLEid=0;
  6575. LPENTRYID lpEid=NULL, lpDLEid = NULL;
  6576. ULONG ulObjType=NULL,cValues=0;
  6577. LPMAILUSER lpUser=NULL, lpDLUser = NULL;
  6578. ULONG cbEidPAB = 0;
  6579. LPENTRYID lpEidPAB = NULL;
  6580. LPMAPITABLE lpContentsTable = NULL, lpDLContentsTable = NULL;
  6581. LPSRowSet lpRowSet = NULL, lpRowSetDL= NULL;
  6582. LPSPropValue lpSPropValue = NULL, lpSPropValueDL = NULL;
  6583. SizedSPropTagArray(2,SPTTagArray) = {2, {PR_DISPLAY_NAME, PR_EMAIL_ADDRESS} };
  6584. LUIOut(L1," ");
  6585. LUIOut(L1,"Running EnumerateAll");
  6586. LUIOut(L2,"-> Enumerates all the entries in the PAB");
  6587. LUIOut(L1," ");
  6588. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  6589. LUIOut(L2,"MapiInitLogon Failed");
  6590. retval = FALSE;
  6591. goto out;
  6592. }
  6593. // Get the IAddrBook
  6594. hr = (lpMAPISession)->OpenAddressBook(
  6595. IN 0, //window handle
  6596. IN NULL, //Interface identifier
  6597. IN 0, //flags
  6598. OUT &lpAdrBook); //pointer to address book object
  6599. if (HR_FAILED(hr)) {
  6600. LUIOut(L2,"OpenAddressBook Failed");
  6601. LUIOut(L3,"Could not open address book for the profile");
  6602. retval=FALSE;
  6603. goto out;
  6604. }
  6605. if(! OpenPABID(IN lpAdrBook, OUT &cbEidPAB,
  6606. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType))
  6607. {
  6608. LUIOut(L2,"OpenPABID Failed");
  6609. LUIOut(L3,"Could not Open PAB");
  6610. retval=FALSE;
  6611. goto out;
  6612. }
  6613. assert(lpPABCont != NULL);
  6614. hr = lpPABCont->GetContentsTable( IN 0, //Flags
  6615. OUT &lpContentsTable);
  6616. if (HR_FAILED(hr)) {
  6617. LUIOut(L2,"GetContentsTable: Failed");
  6618. retval=FALSE;
  6619. goto out;
  6620. }
  6621. assert(lpRowSet == NULL);
  6622. assert(lpRowSetDL == NULL);
  6623. assert(lpContentsTable != NULL);
  6624. while(!HR_FAILED(hr = lpContentsTable->QueryRows(IN 1,
  6625. IN 0,
  6626. OUT &lpRowSet))) {
  6627. assert(lpRowSet != NULL);
  6628. bDistList = FALSE;
  6629. if (lpRowSet->cRows) {
  6630. ulEntries++;
  6631. i=0;
  6632. while(lpRowSet->aRow[0].lpProps[i].ulPropTag != PR_ENTRYID )
  6633. if (++i >= (int) lpRowSet->aRow[0].cValues)
  6634. {
  6635. LUIOut( L2, "Didn't find PR_ENTRYID in the row!" );
  6636. retval=FALSE;
  6637. goto out;
  6638. }
  6639. cbEid = lpRowSet->aRow[0].lpProps[i].Value.bin.cb;
  6640. lpEid = (LPENTRYID)lpRowSet->aRow[0].lpProps[i].Value.bin.lpb;
  6641. assert(lpEid != NULL);
  6642. // Is this a DL
  6643. i=0;
  6644. while(lpRowSet->aRow[0].lpProps[i].ulPropTag != PR_OBJECT_TYPE )
  6645. if (++i >= (int) lpRowSet->aRow[0].cValues)
  6646. {
  6647. LUIOut( L2, "Didn't find PR_OBJECT_TYPE in the row!" );
  6648. retval=FALSE;
  6649. goto out;
  6650. }
  6651. if (lpRowSet->aRow[0].lpProps[i].Value.ul == MAPI_DISTLIST)
  6652. bDistList = TRUE;
  6653. //d lpUser = NULL;
  6654. assert(lpUser == NULL);
  6655. assert(lpPABCont != NULL);
  6656. hr = lpPABCont->OpenEntry(
  6657. IN cbEid,
  6658. IN lpEid,
  6659. IN NULL, //default interface
  6660. IN MAPI_BEST_ACCESS, //flags
  6661. OUT &ulObjType,
  6662. OUT (LPUNKNOWN *) &lpUser);
  6663. if (HR_FAILED(hr)) {
  6664. LUIOut(L2,"OpenEntry Failed");
  6665. retval=FALSE;
  6666. goto out;
  6667. }
  6668. else
  6669. {
  6670. //d assert(lpUser != NULL);
  6671. //LUIOut( L2,"OpenEntry on EntryID for User Passed" );
  6672. assert(lpUser != NULL);
  6673. hr = lpUser->GetProps(
  6674. IN (LPSPropTagArray) &SPTTagArray,
  6675. IN 0,
  6676. OUT &cValues,
  6677. OUT &lpSPropValue);
  6678. if ((HR_FAILED(hr))||(PropError(lpSPropValue->ulPropTag, cValues))) {
  6679. {
  6680. LUIOut( L2,"GetProps on User Object failed" );
  6681. }
  6682. else
  6683. {
  6684. LUIOut(L2,"Entry Name: %s",lpSPropValue->Value.LPSZ);
  6685. if (lpSPropValue) {
  6686. MAPIFreeBuffer(lpSPropValue);
  6687. lpSPropValue = NULL;
  6688. }
  6689. assert(lpSPropValue == NULL);
  6690. }
  6691. /* */
  6692. if (bDistList) {
  6693. //d lpDLCont = NULL;
  6694. assert(lpDLCont == NULL);
  6695. assert(lpPABCont != NULL);
  6696. hr = lpPABCont->OpenEntry(
  6697. IN cbEid,
  6698. IN lpEid,
  6699. IN NULL, //default interface
  6700. IN MAPI_BEST_ACCESS, //flags
  6701. OUT &ulObjType,
  6702. OUT (LPUNKNOWN *) &lpDLCont);
  6703. if (HR_FAILED(hr)) {
  6704. LUIOut(L2,"OpenEntry Failed");
  6705. retval=FALSE;
  6706. goto out;
  6707. }
  6708. //d set to NULL?
  6709. assert(lpDLContentsTable == NULL);
  6710. assert(lpDLCont != NULL);
  6711. hr = lpDLCont->GetContentsTable( IN 0, //Flags
  6712. OUT &lpDLContentsTable);
  6713. if (HR_FAILED(hr)) {
  6714. LUIOut(L2,"GetContentsTable: Failed");
  6715. retval=FALSE;
  6716. goto out;
  6717. }
  6718. assert(lpRowSetDL == NULL);
  6719. assert(lpDLContentsTable != NULL);
  6720. while(!HR_FAILED(hr = lpDLContentsTable->QueryRows(IN 1,
  6721. IN 0,
  6722. OUT &lpRowSetDL))) {
  6723. if (lpRowSetDL->cRows) {
  6724. ulEntriesDL++;
  6725. j=0;
  6726. while(lpRowSetDL->aRow[0].lpProps[j].ulPropTag != PR_ENTRYID )
  6727. if (++j >= (int) lpRowSetDL->aRow[0].cValues)
  6728. {
  6729. LUIOut( L2, "Didn't find PR_ENTRYID in the row!" );
  6730. retval=FALSE;
  6731. goto out;
  6732. }
  6733. cbDLEid = lpRowSetDL->aRow[0].lpProps[j].Value.bin.cb;
  6734. lpDLEid = (LPENTRYID)lpRowSetDL->aRow[0].lpProps[j].Value.bin.lpb;
  6735. assert(lpDLEid != NULL);
  6736. //d lpDLUser = NULL;
  6737. //d assert(lpDLUser == NULL);
  6738. assert(lpDLCont != NULL);
  6739. hr = lpDLCont->OpenEntry(
  6740. IN cbDLEid,
  6741. IN lpDLEid,
  6742. IN NULL, //default interface
  6743. IN MAPI_BEST_ACCESS, //flags
  6744. OUT &ulObjType,
  6745. OUT (LPUNKNOWN *) &lpDLUser);
  6746. if (HR_FAILED(hr)) {
  6747. LUIOut(L2,"OpenEntry Failed");
  6748. retval=FALSE;
  6749. goto out;
  6750. }
  6751. else
  6752. {
  6753. assert(lpSPropValueDL == NULL);
  6754. //LUIOut( L2,"OpenEntry on EntryID for User Passed" );
  6755. assert(lpDLUser != NULL);
  6756. hr = lpDLUser->GetProps(
  6757. IN (LPSPropTagArray) &SPTTagArray,
  6758. IN 0,
  6759. OUT &cValues,
  6760. OUT &lpSPropValueDL);
  6761. if ((HR_FAILED(hr))||(PropError(lpSPropValueDL->ulPropTag, cValues))) {
  6762. assert( lpSPropValueDL == NULL);
  6763. LUIOut( L3,"GetProps on User Object failed" );
  6764. }
  6765. else {
  6766. LUIOut(L3,"Entry Name: %s",lpSPropValueDL->Value.LPSZ);
  6767. assert( lpSPropValueDL != NULL);
  6768. if (lpSPropValueDL) {
  6769. MAPIFreeBuffer(lpSPropValueDL);
  6770. lpSPropValueDL = NULL;
  6771. }
  6772. assert( lpSPropValueDL == NULL);
  6773. }
  6774. }
  6775. if (lpRowSetDL) {
  6776. FreeProws( lpRowSetDL );
  6777. lpRowSetDL = NULL;
  6778. }
  6779. assert( lpRowSetDL == NULL);
  6780. if(lpDLUser) {
  6781. lpDLUser->Release();
  6782. lpDLUser = NULL;
  6783. }
  6784. /* */ }
  6785. else // no more rows in table
  6786. {
  6787. //Free Row
  6788. if (lpRowSetDL) {
  6789. FreeProws(lpRowSetDL);
  6790. lpRowSetDL = NULL;
  6791. }
  6792. assert( lpRowSetDL == NULL);
  6793. break;
  6794. }
  6795. if(ulEntriesDL == 50) // we only handle the first 50 entries otherwise this would take forever
  6796. break;
  6797. assert(lpRowSetDL == NULL);
  6798. //***//
  6799. }
  6800. if (lpDLCont)
  6801. lpDLCont->Release();
  6802. lpDLCont = NULL;
  6803. assert(lpRowSetDL == NULL);
  6804. if (lpDLContentsTable)
  6805. lpDLContentsTable->Release();
  6806. lpDLContentsTable = NULL;
  6807. }
  6808. }
  6809. //Free Row
  6810. if (lpRowSet) {
  6811. FreeProws(lpRowSet);
  6812. lpRowSet = NULL;
  6813. }
  6814. assert( lpRowSet == NULL);
  6815. }
  6816. else // no more rows in table
  6817. {
  6818. //Free Row
  6819. if (lpRowSet) {
  6820. FreeProws(lpRowSet);
  6821. lpRowSet = NULL;
  6822. }
  6823. assert( lpRowSet == NULL);
  6824. break;
  6825. }
  6826. if(ulEntries == 50) // we only handle the first 50 entries otherwise this would take forever
  6827. break;
  6828. assert(lpRowSet == NULL);
  6829. assert(lpRowSetDL == NULL);
  6830. assert(lpContentsTable != NULL);
  6831. if(lpUser) {
  6832. lpUser->Release();
  6833. lpUser = NULL;
  6834. }
  6835. }//while
  6836. assert(lpRowSet == NULL);
  6837. assert(lpRowSetDL == NULL);
  6838. LUIOut(L2,"Total Entries: %d", ulEntries);
  6839. if (HR_FAILED(hr)){
  6840. LUIOut(L2,"QueryRows Failed");
  6841. retval = FALSE;
  6842. goto out;
  6843. }
  6844. out:
  6845. if (lpSPropValue)
  6846. MAPIFreeBuffer(lpSPropValue);
  6847. if (lpSPropValueDL)
  6848. MAPIFreeBuffer(lpSPropValueDL);
  6849. if (lpContentsTable)
  6850. lpContentsTable->Release();
  6851. if (lpDLContentsTable)
  6852. lpDLContentsTable->Release();
  6853. if (lpPABCont)
  6854. lpPABCont->Release();
  6855. if (lpDLCont)
  6856. lpDLCont->Release();
  6857. if (lpEidPAB)
  6858. MAPIFreeBuffer(lpEidPAB);
  6859. if (lpAdrBook)
  6860. lpAdrBook->Release();
  6861. if (lpMAPISession)
  6862. lpMAPISession->Release();
  6863. MAPIUninitialize();
  6864. #endif
  6865. return retval;
  6866. }
  6867. BOOL ClearPab(int bMAILUSERS)
  6868. {
  6869. // Clear PAB of all the entries. If bMailUsers flag is TRUE,
  6870. // then only clear MAILUSERS, else clear everything.
  6871. ULONG ulFlags = 0;
  6872. HRESULT hr = hrSuccess;
  6873. SCODE sc = SUCCESS_SUCCESS;
  6874. int retval=TRUE;
  6875. #ifdef PAB
  6876. LPMAPISESSION lpMAPISession = NULL;
  6877. LPADRBOOK lpAdrBook = NULL;
  6878. LPABCONT lpPABCont= NULL;
  6879. ULONG cbEidPAB = 0;
  6880. LPENTRYID lpEidPAB = NULL;
  6881. //char szDispName[BIG_BUF];
  6882. ULONG cValues = 0;
  6883. //int cEntriesToDelete;
  6884. int i=0,k=0;
  6885. //char szEntryTag[SML_BUF];
  6886. //char szTagBuf[SML_BUF];
  6887. ULONG cRows = 0;
  6888. ULONG iEntry = 0;
  6889. LPMAPITABLE lpContentsTable = NULL;
  6890. LPSRowSet lpRowSet = NULL;
  6891. SPropValue PropValue = {0};
  6892. LPSPropValue lpSPropValue = NULL;
  6893. SizedSPropTagArray(3, Cols) = { 3, {PR_DISPLAY_NAME, PR_ENTRYID, PR_OBJECT_TYPE } };
  6894. LPENTRYLIST lpEntryList=NULL;
  6895. ULONG cbEid=0;
  6896. LPENTRYID lpEid=NULL;
  6897. LPVOID *lpEid2=NULL;
  6898. LUIOut(L1," ");
  6899. if (bMAILUSERS) {
  6900. LUIOut(L1,"Running DeleteUsersOnly");
  6901. LUIOut(L2,"-> Deletes mail users Only (not distribution lists) from the PAB");
  6902. LUIOut(L1," ");
  6903. }
  6904. else {
  6905. LUIOut(L1,"Running Delete All Entries");
  6906. LUIOut(L2,"-> Clears the PAB");
  6907. LUIOut(L1," ");
  6908. }
  6909. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  6910. LUIOut(L2,"MapiInitLogon Failed");
  6911. retval = FALSE;
  6912. goto out;
  6913. }
  6914. // Get the IAddrBook
  6915. hr = (lpMAPISession)->OpenAddressBook(
  6916. IN 0, //window handle
  6917. IN NULL, //Interface identifier
  6918. IN 0, //flags
  6919. OUT &lpAdrBook); //pointer to address book object
  6920. if (HR_FAILED(hr)) {
  6921. LUIOut(L2,"OpenAddressBook Failed");
  6922. LUIOut(L3,"Could not open address book for the profile");
  6923. retval=FALSE;
  6924. goto out;
  6925. }
  6926. // OpenPAB
  6927. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  6928. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType);
  6929. if (HR_FAILED(hr)) {
  6930. LUIOut(L2,"OpenPABID Failed");
  6931. LUIOut(L3,"Could not Open PAB");
  6932. retval=FALSE;
  6933. goto out;
  6934. }
  6935. //
  6936. // Get the Contents Table for the PAB container
  6937. //
  6938. hr = lpPABCont->GetContentsTable( IN 0, //Flags
  6939. OUT &lpContentsTable);
  6940. if (HR_FAILED(hr)) {
  6941. LUIOut(L3,"GetContentsTable: Failed");
  6942. goto out;
  6943. }
  6944. //
  6945. // Only interested in 2 columns:
  6946. // PR_DISPLAY_NAME and PR_ENTRYID
  6947. //
  6948. hr = lpContentsTable->SetColumns(IN (LPSPropTagArray) &Cols,
  6949. IN 0);
  6950. if (HR_FAILED(hr)) {
  6951. LUIOut(L3,"SetColumns Failed");
  6952. retval = FALSE;
  6953. goto out;
  6954. }
  6955. // Query and delete 1 row at a time
  6956. do
  6957. {
  6958. hr = lpContentsTable->QueryRows(IN 1,
  6959. IN 0,
  6960. OUT &lpRowSet);
  6961. if (HR_FAILED(hr)){
  6962. LUIOut(L3,"QueryRows Failed");
  6963. retval = FALSE;
  6964. goto out;
  6965. }
  6966. cRows = lpRowSet->cRows;
  6967. for (iEntry = 0; iEntry < cRows; iEntry++)
  6968. {
  6969. //
  6970. // For each entry, process it.
  6971. //
  6972. lpSPropValue = lpRowSet->aRow[iEntry].lpProps;
  6973. if (lpSPropValue[1].ulPropTag == PR_ENTRYID)
  6974. {
  6975. // don't delete this since it is not a mail user
  6976. //
  6977. if ((!bMAILUSERS) || (bMAILUSERS &&(lpSPropValue[2].ulPropTag == PR_OBJECT_TYPE)
  6978. && (lpSPropValue[2].Value.ul == MAPI_MAILUSER))) {
  6979. cbEid = lpSPropValue[1].Value.bin.cb;
  6980. lpEid = (LPENTRYID) lpSPropValue[1].Value.bin.lpb;
  6981. hr = HrCreateEntryListFromID(lpLocalWABObject, IN cbEid,
  6982. IN lpEid,
  6983. OUT &lpEntryList);
  6984. if (HR_FAILED(hr)) {
  6985. LUIOut(L3,"Could not Create Entry List");
  6986. retval=FALSE;
  6987. goto out;
  6988. }
  6989. //
  6990. // Then pass the lpEntryList to DeleteEntries to delete ...
  6991. //
  6992. hr = lpPABCont->DeleteEntries(IN lpEntryList,IN 0);
  6993. if (HR_FAILED(hr)) {
  6994. LUIOut(L3,"Could not Delete Entry %s", lpSPropValue[0].Value.LPSZ);
  6995. retval=FALSE;
  6996. goto out;
  6997. } else LUIOut(L3,"Deleted Entry: %s", lpSPropValue[0].Value.LPSZ);
  6998. }
  6999. }
  7000. }
  7001. if(lpRowSet) {
  7002. FreeProws(lpRowSet);
  7003. lpRowSet = NULL;
  7004. }
  7005. }while((0!=cRows) && (0==!(cbEid)));
  7006. out:
  7007. if(lpRowSet)
  7008. FreeProws(lpRowSet);
  7009. if (lpSPropValue)
  7010. MAPIFreeBuffer(lpSPropValue);
  7011. if (lpContentsTable)
  7012. lpContentsTable->Release();
  7013. if (lpEid)
  7014. MAPIFreeBuffer(lpEid);
  7015. if (lpPABCont)
  7016. lpPABCont->Release();
  7017. if (lpEidPAB)
  7018. MAPIFreeBuffer(lpEidPAB);
  7019. if (lpAdrBook)
  7020. lpAdrBook->Release();
  7021. if (lpMAPISession)
  7022. lpMAPISession->Release();
  7023. MAPIUninitialize();
  7024. #endif
  7025. return retval;
  7026. }
  7027. BOOL CreateOneOff()
  7028. {
  7029. ULONG ulFlags = 0;
  7030. HRESULT hr = hrSuccess;
  7031. SCODE sc = SUCCESS_SUCCESS;
  7032. int retval=TRUE;
  7033. #ifdef PAB
  7034. LPMAPISESSION lpMAPISession = NULL;
  7035. LPADRBOOK lpAdrBook = NULL;
  7036. LPABCONT lpPABCont= NULL;
  7037. // ULONG cbEidPAB = 0;
  7038. // LPENTRYID lpEidPAB = NULL;
  7039. ULONG cbEid=0, cValues;
  7040. LPENTRYID lpEid=NULL;
  7041. ULONG ulObjType=NULL;
  7042. LPMAILUSER lpUser=NULL;
  7043. char szDispName[BIG_BUF];
  7044. char szAddressType[BIG_BUF];
  7045. char szEmailAddress[BIG_BUF];
  7046. LPSPropValue lpSPropValue = NULL;
  7047. SizedSPropTagArray(5,SPTTagArray) = {5, {PR_DISPLAY_NAME,
  7048. PR_ADDRTYPE, PR_EMAIL_ADDRESS,
  7049. PR_OBJECT_TYPE,PR_ENTRYID} };
  7050. LUIOut(L1," ");
  7051. LUIOut(L1,"Running CreateOneOff");
  7052. LUIOut(L2,"-> Creates a one off entry as specified, in the PAB");
  7053. LUIOut(L3,"And then verifies the properties of the entry created");
  7054. LUIOut(L1," ");
  7055. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  7056. LUIOut(L2,"MapiInitLogon Failed");
  7057. retval = FALSE;
  7058. goto out;
  7059. }
  7060. // Get the IAddrBook
  7061. hr = (lpMAPISession)->OpenAddressBook(
  7062. IN 0, //window handle
  7063. IN NULL, //Interface identifier
  7064. IN 0, //flags
  7065. OUT &lpAdrBook); //pointer to address book object
  7066. if (HR_FAILED(hr)) {
  7067. LUIOut(L2,"OpenAddressBook Failed");
  7068. LUIOut(L3,"Could not open address book for the profile");
  7069. retval=FALSE;
  7070. goto out;
  7071. }
  7072. // Get the details of the Entry to Create from INI file
  7073. GetPrivateProfileString("CreateOneOff","Name","",szDispName,BIG_BUF,INIFILENAME);
  7074. GetPrivateProfileString("CreateOneOff","AddressType","",szAddressType,BIG_BUF,INIFILENAME);
  7075. GetPrivateProfileString("CreateOneOff","EmailAddress","",szEmailAddress,BIG_BUF,INIFILENAME);
  7076. hr = lpAdrBook->CreateOneOff(szDispName,szAddressType,szEmailAddress,NULL,&cbEid,&lpEid);
  7077. if (HR_FAILED(hr)) {
  7078. LUIOut(L2,"CreateOneOff Failed");
  7079. retval=FALSE;
  7080. goto out;
  7081. }
  7082. //Verification
  7083. hr = lpAdrBook->OpenEntry(IN cbEid, IN lpEid, IN NULL, MAPI_BEST_ACCESS,
  7084. OUT & ulObjType,(LPUNKNOWN *) &lpUser);
  7085. if (HR_FAILED(hr)) {
  7086. LUIOut(L2,"OpenEntry Failed");
  7087. retval=FALSE;
  7088. goto out;
  7089. } else LUIOut(L2,"OpenEntry Succeeded");
  7090. hr = lpUser->GetProps(
  7091. IN (LPSPropTagArray) &SPTTagArray,
  7092. IN 0,
  7093. OUT &cValues,
  7094. OUT &lpSPropValue);
  7095. if ((HR_FAILED(hr))||(PropError(lpSPropValue->ulPropTag, cValues))) {
  7096. LUIOut( L2,"GetProps on User Object failed" );
  7097. else {
  7098. LUIOut(L2,"Entry Name: %s",(lpSPropValue[0]).Value.LPSZ);
  7099. if (lstrcmpi((lpSPropValue[0]).Value.LPSZ, (LPSTR)szDispName))
  7100. retval = FALSE;
  7101. LUIOut(L2,"AddressType: %s",(lpSPropValue[1]).Value.LPSZ);
  7102. if (lstrcmpi((lpSPropValue[1]).Value.LPSZ, (LPSTR)szAddressType))
  7103. retval = FALSE;
  7104. LUIOut(L2,"EmailAddress: %s",(lpSPropValue[2]).Value.LPSZ);
  7105. if (lstrcmpi((lpSPropValue[2]).Value.LPSZ, (LPSTR)szEmailAddress))
  7106. retval = FALSE;
  7107. LUIOut(L2,"ObjectType: %0x",(lpSPropValue[3]).Value.ul);
  7108. if ((lpSPropValue[3]).Value.ul != MAPI_MAILUSER)
  7109. retval = FALSE;
  7110. }
  7111. out:
  7112. if (lpSPropValue)
  7113. MAPIFreeBuffer(lpSPropValue);
  7114. if (lpEid)
  7115. MAPIFreeBuffer(lpEid);
  7116. if (lpAdrBook)
  7117. lpAdrBook->Release();
  7118. if (lpMAPISession)
  7119. lpMAPISession->Release();
  7120. MAPIUninitialize();
  7121. #endif
  7122. return retval;
  7123. }
  7124. BOOL PABResolveName()
  7125. {
  7126. HRESULT hr = hrSuccess;
  7127. int retval=TRUE;
  7128. #ifdef PAB
  7129. LPMAPISESSION lpMAPISession = NULL;
  7130. LPADRBOOK lpAdrBook = NULL;
  7131. ULONG cEntries=0;
  7132. LPADRLIST lpAdrList = NULL, lpAdrListNew = NULL;
  7133. int temp1=0, temp2 =0, temp3=0, temp4=0;
  7134. char szResName[10][BIG_BUF];
  7135. int i = 0;
  7136. LUIOut(L1," ");
  7137. LUIOut(L1,"Running ResolveName");
  7138. LUIOut(L2,"-> Does Name Resolution Tests on PAB");
  7139. LUIOut(L1," ");
  7140. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  7141. LUIOut(LFAIL2,"MapiInitLogon Failed");
  7142. retval = FALSE;
  7143. goto out;
  7144. }
  7145. // Get the IAddrBook
  7146. hr = (lpMAPISession)->OpenAddressBook(
  7147. IN 0, //window handle
  7148. IN NULL, //Interface identifier
  7149. IN 0, //flags
  7150. OUT &lpAdrBook); //pointer to address book object
  7151. if (HR_FAILED(hr)) {
  7152. LUIOut(LFAIL2,"OpenAddressBook Failed");
  7153. LUIOut(L3,"Could not open address book for the profile");
  7154. retval=FALSE;
  7155. goto out;
  7156. }
  7157. cEntries = 1;
  7158. GetPrivateProfileString("ResolveName","ResName1","",szResName[0],BIG_BUF,INIFILENAME);
  7159. LUIOut(L2,"Step1: Resolve unresolved name");
  7160. LUIOut(L3,"Name to resolve: %s",szResName[0]);
  7161. temp1 = sizeof(ADRLIST) + cEntries*(sizeof(ADRENTRY));
  7162. temp2 = CbNewADRLIST(cEntries);
  7163. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrList );
  7164. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[0].rgPropVals));
  7165. lpAdrList->cEntries = cEntries;
  7166. lpAdrList->aEntries[0].cValues = 1;
  7167. lpAdrList->aEntries[0].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7168. lpAdrList->aEntries[0].rgPropVals->dwAlignPad = 0;
  7169. lpAdrList->aEntries[0].rgPropVals->Value.LPSZ = szResName[0];
  7170. hr = lpAdrBook->ResolveName((ULONG)GetActiveWindow(), MAPI_DIALOG, NULL, lpAdrList);
  7171. if (HR_FAILED(hr)) {
  7172. LUIOut(LFAIL4,"ResolveName Failed for %s",lpAdrList->aEntries[0].rgPropVals->Value.LPSZ);
  7173. retval=FALSE;
  7174. goto out;
  7175. }
  7176. else LUIOut(LPASS4,"Resolved successfully");
  7177. if (ValidateAdrList(lpAdrList, cEntries))
  7178. LUIOut(LPASS4,"Validation passed");
  7179. else {
  7180. LUIOut(LFAIL4,"Validation unsuccessful");
  7181. retval = FALSE;
  7182. }
  7183. LUIOut(L2,"Step2: Resolve the previously resolved name");
  7184. hr = lpAdrBook->ResolveName(0, 0, NULL, lpAdrList);
  7185. if (HR_FAILED(hr)) {
  7186. LUIOut(LFAIL4,"ResolveName Failed for %s",lpAdrList->aEntries[0].rgPropVals->Value.LPSZ);
  7187. retval=FALSE;
  7188. goto out;
  7189. }
  7190. else LUIOut(LPASS4,"Resolved successfully");
  7191. LUIOut(L4,"Validate the returned PropList");
  7192. if (ValidateAdrList(lpAdrList, cEntries))
  7193. LUIOut(LPASS4,"Validation passed");
  7194. else {
  7195. LUIOut(LFAIL4,"Validation unsuccessful");
  7196. retval = FALSE;
  7197. }
  7198. MAPIFreeBuffer( lpAdrList->aEntries[0].rgPropVals );
  7199. MAPIFreeBuffer( lpAdrList );
  7200. lpAdrList = NULL;
  7201. LUIOut(L2,"Step3: Resolve mixed names");
  7202. LUIOut(L2,"->prev. resolved and unresolved");
  7203. LUIOut(L3,"Step3a: Resolve following unresolved names: ");
  7204. GetPrivateProfileString("ResolveName","ResName2","",szResName[1],BIG_BUF,INIFILENAME);
  7205. GetPrivateProfileString("ResolveName","ResName3","",szResName[2],BIG_BUF,INIFILENAME);
  7206. GetPrivateProfileString("ResolveName","ResName4","",szResName[3],BIG_BUF,INIFILENAME);
  7207. LUIOut(L4,"%s",szResName[1]);
  7208. LUIOut(L4,"%s",szResName[2]);
  7209. LUIOut(L4,"%s",szResName[3]);
  7210. cEntries = 3;
  7211. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrList );
  7212. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[0].rgPropVals));
  7213. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[1].rgPropVals));
  7214. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[2].rgPropVals));
  7215. lpAdrList->cEntries = cEntries;
  7216. // Name 1
  7217. lpAdrList->aEntries[0].cValues = 1;
  7218. lpAdrList->aEntries[0].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7219. lpAdrList->aEntries[0].rgPropVals->Value.LPSZ = szResName[1];
  7220. // Name 2
  7221. lpAdrList->aEntries[1].cValues = 1;
  7222. lpAdrList->aEntries[1].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7223. lpAdrList->aEntries[1].rgPropVals->Value.LPSZ = szResName[2];
  7224. // Name 3
  7225. lpAdrList->aEntries[2].cValues = 1;
  7226. lpAdrList->aEntries[2].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7227. lpAdrList->aEntries[2].rgPropVals->Value.LPSZ = szResName[3];
  7228. if(HR_FAILED(lpAdrBook->ResolveName((ULONG)GetActiveWindow(), MAPI_DIALOG, NULL, lpAdrList))) {
  7229. LUIOut( LFAIL4, "ResolveName failed for unresolved names" );
  7230. retval = FALSE;
  7231. goto out;
  7232. }
  7233. LUIOut( LPASS4, "ResolveName passed for unresolved names." );
  7234. //Validate the AdrList
  7235. LUIOut(L4,"Validate the returned PropList");
  7236. if (ValidateAdrList(lpAdrList, cEntries))
  7237. LUIOut(LPASS4,"Validation passed");
  7238. else {
  7239. LUIOut(LFAIL4,"Validation unsuccessful");
  7240. retval = FALSE;
  7241. }
  7242. // Now add two unresolved names to the AdrList
  7243. LUIOut(L4,"Step3b: Add the following unresolved names to the list: ");
  7244. GetPrivateProfileString("ResolveName","ResName5","",szResName[4],BIG_BUF,INIFILENAME);
  7245. GetPrivateProfileString("ResolveName","ResName6","",szResName[5],BIG_BUF,INIFILENAME);
  7246. LUIOut(L4,"%s",szResName[4]);
  7247. LUIOut(L4,"%s",szResName[5]);
  7248. cEntries = 5;
  7249. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrListNew);
  7250. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrListNew->aEntries[1].rgPropVals));
  7251. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrListNew->aEntries[3].rgPropVals));
  7252. lpAdrListNew->cEntries = cEntries;
  7253. // Name 2
  7254. lpAdrListNew->aEntries[1].cValues = 1;
  7255. lpAdrListNew->aEntries[1].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7256. lpAdrListNew->aEntries[1].rgPropVals->Value.LPSZ = szResName[4];
  7257. // Name 4
  7258. lpAdrListNew->aEntries[3].cValues = 1;
  7259. lpAdrListNew->aEntries[3].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7260. lpAdrListNew->aEntries[3].rgPropVals->Value.LPSZ = szResName[5];
  7261. lpAdrListNew->aEntries[0] = lpAdrList->aEntries[0];
  7262. lpAdrListNew->aEntries[2] = lpAdrList->aEntries[1];
  7263. lpAdrListNew->aEntries[4] = lpAdrList->aEntries[2];
  7264. MAPIFreeBuffer(lpAdrList);
  7265. lpAdrList = NULL;
  7266. lpAdrList = lpAdrListNew;
  7267. // call ResolveName() w/ a mix of resolved and unresolved.
  7268. if(HR_FAILED(lpAdrBook->ResolveName((ULONG) GetActiveWindow(), MAPI_DIALOG, NULL, lpAdrList)))
  7269. {
  7270. LUIOut( LFAIL4, "ResolveName failed with resolved and unresolved names" );
  7271. retval = FALSE;
  7272. goto out;
  7273. }
  7274. LUIOut( LPASS4, "ResolveName passed with resolved and unresolved names" );
  7275. //Validate the AdrList
  7276. LUIOut(L4,"Validate the returned PropList");
  7277. if (ValidateAdrList(lpAdrList, cEntries))
  7278. LUIOut(LPASS4,"Validation passed");
  7279. else {
  7280. LUIOut(LFAIL4,"Validation unsuccessful");
  7281. retval = FALSE;
  7282. }
  7283. for(i=0; i<(int) cEntries; ++i)
  7284. MAPIFreeBuffer(lpAdrList->aEntries[i].rgPropVals);
  7285. MAPIFreeBuffer(lpAdrList );
  7286. lpAdrList = NULL;
  7287. GetPrivateProfileString("ResolveName","NonExistentName","",szResName[6],BIG_BUF,INIFILENAME);
  7288. LUIOut(L3,"Step 4: Resolve non existent name");
  7289. LUIOut(L3,"Name: %s",szResName[6]);
  7290. //call ResolveName() with a non-existant name
  7291. cEntries = 1;
  7292. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrList);
  7293. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[0].rgPropVals));
  7294. lpAdrList->cEntries = cEntries;
  7295. lpAdrList->aEntries[0].cValues = 1;
  7296. lpAdrList->aEntries[0].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7297. lpAdrList->aEntries[0].rgPropVals->Value.LPSZ = szResName[6];
  7298. if(lpAdrBook->ResolveName(0,0, NULL,lpAdrList) != MAPI_E_NOT_FOUND)
  7299. {
  7300. LUIOut( LFAIL4, "ResolveName did not return NOT FOUND" );
  7301. retval = FALSE;
  7302. goto out;
  7303. }
  7304. LUIOut( LPASS4, "ResolveName correctly returned MAPI_E_NOT_FOUND." );
  7305. MAPIFreeBuffer(lpAdrList->aEntries[0].rgPropVals );
  7306. MAPIFreeBuffer(lpAdrList );
  7307. lpAdrList = NULL;
  7308. //call ResolveName() w/ just the ambiguous name
  7309. cEntries = 1;
  7310. GetPrivateProfileString("ResolveName","AmbigousName","",szResName[7],BIG_BUF,INIFILENAME);
  7311. LUIOut(L2,"Step5: Resolve ambigous name");
  7312. LUIOut(L3,"Name: %s",szResName[7]);
  7313. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrList);
  7314. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[0].rgPropVals));
  7315. lpAdrList->cEntries = cEntries;
  7316. lpAdrList->aEntries[0].cValues = 1;
  7317. lpAdrList->aEntries[0].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7318. lpAdrList->aEntries[0].rgPropVals->Value.LPSZ = szResName[7];
  7319. if (hr = lpAdrBook->ResolveName((ULONG)GetActiveWindow(),MAPI_DIALOG, NULL, lpAdrList)
  7320. &&( hr != MAPI_E_AMBIGUOUS_RECIP)) {
  7321. LUIOut(LFAIL4, "ResolveName failed for name that was not specific enough");
  7322. retval = FALSE;
  7323. goto out;
  7324. }
  7325. else LUIOut(LPASS4,"ResolveName correctly returned MAPI_E_AMBUGUOUS_RECIP." );
  7326. MAPIFreeBuffer(lpAdrList->aEntries[0].rgPropVals);
  7327. MAPIFreeBuffer(lpAdrList);
  7328. lpAdrList = NULL;
  7329. //Resolves name using the oneoff provider
  7330. cEntries = 1;
  7331. GetPrivateProfileString("ResolveName","OneOffAddress","",szResName[8],BIG_BUF,INIFILENAME);
  7332. LUIOut(L2,"Resolve OneOff Name");
  7333. LUIOut(L3,"OneOff Address: %s",szResName[8]);
  7334. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrList);
  7335. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[0].rgPropVals));
  7336. lpAdrList->cEntries = cEntries;
  7337. lpAdrList->aEntries[0].cValues = 1;
  7338. lpAdrList->aEntries[0].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  7339. lpAdrList->aEntries[0].rgPropVals->Value.LPSZ = szResName[8];
  7340. if(HR_FAILED(lpAdrBook->ResolveName(0,0, NULL, lpAdrList)))
  7341. {
  7342. LUIOut( LFAIL4, "ResolveName failed for OneOffAddress" );
  7343. retval = FALSE;
  7344. goto out;
  7345. }
  7346. LUIOut( LPASS4, "ResolveName passed for OneOffAddress" );
  7347. //Validate the AdrList
  7348. LUIOut(L4,"Validate the returned PropList");
  7349. if (ValidateAdrList(lpAdrList, cEntries))
  7350. LUIOut(LPASS4,"Validation passed");
  7351. else {
  7352. LUIOut(LFAIL4,"Validation unsuccessful");
  7353. retval = FALSE;
  7354. }
  7355. MAPIFreeBuffer(lpAdrList->aEntries[0].rgPropVals);
  7356. MAPIFreeBuffer(lpAdrList );
  7357. lpAdrList = NULL;
  7358. cEntries = 0;
  7359. out:
  7360. if (cEntries > 0)
  7361. for (i=0;i<(int)cEntries; i++) {
  7362. MAPIFreeBuffer( lpAdrList->aEntries[i].rgPropVals );
  7363. }
  7364. if (lpAdrList) {
  7365. MAPIFreeBuffer( lpAdrList );
  7366. lpAdrList = NULL;
  7367. }
  7368. if (lpAdrBook)
  7369. lpAdrBook->Release();
  7370. if (lpMAPISession)
  7371. lpMAPISession->Release();
  7372. MAPIUninitialize();
  7373. #endif
  7374. return retval;
  7375. }
  7376. BOOL PABSetProps()
  7377. {
  7378. HRESULT hr = hrSuccess;
  7379. int retval=TRUE;
  7380. #ifdef PAB
  7381. int i=0;
  7382. int bFound = FALSE;
  7383. LPMAPISESSION lpMAPISession = NULL;
  7384. LPADRBOOK lpAdrBook = NULL;
  7385. SPropValue PropValue[3];
  7386. LPSPropValue lpSPropValue = NULL;
  7387. ULONG cbEidPAB = 0;
  7388. LPENTRYID lpEidPAB = NULL;
  7389. LPABCONT lpPABCont= NULL;
  7390. LPMAILUSER lpUser=NULL;
  7391. LPMAPITABLE lpContentsTable = NULL;
  7392. LPSRowSet lpRowSet = NULL;
  7393. ULONG cbEid=0, cValues;
  7394. LPENTRYID lpEid=NULL;
  7395. ULONG ulObjType=NULL;
  7396. char szLocation[SML_BUF],szComment[SML_BUF];
  7397. SizedSPropTagArray(3,SPTTagArray) = {3, {PR_DISPLAY_NAME,
  7398. PR_OFFICE_LOCATION, PR_COMMENT} };
  7399. LUIOut(L1," ");
  7400. LUIOut(L1,"Running SetProps");
  7401. LUIOut(L2,"-> Sets properties on a MailUser in the PAB");
  7402. LUIOut(L1," ");
  7403. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  7404. LUIOut(L2,"MapiInitLogon Failed");
  7405. retval = FALSE;
  7406. goto out;
  7407. }
  7408. // Get the IAddrBook
  7409. hr = (lpMAPISession)->OpenAddressBook(
  7410. IN 0, //window handle
  7411. IN NULL, //Interface identifier
  7412. IN 0, //flags
  7413. OUT &lpAdrBook); //pointer to address book object
  7414. if (HR_FAILED(hr)) {
  7415. LUIOut(L2,"OpenAddressBook Failed");
  7416. LUIOut(L3,"Could not open address book for the profile");
  7417. retval=FALSE;
  7418. goto out;
  7419. }
  7420. if(!OpenPABID(IN lpAdrBook, OUT &cbEidPAB,
  7421. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType))
  7422. {
  7423. LUIOut(L2,"OpenPABID Failed");
  7424. LUIOut(L3,"Could not Open PAB");
  7425. retval=FALSE;
  7426. goto out;
  7427. }
  7428. assert(lpPABCont != NULL);
  7429. assert(lpContentsTable == NULL);
  7430. hr = lpPABCont->GetContentsTable( IN 0, //Flags
  7431. OUT &lpContentsTable);
  7432. if (HR_FAILED(hr)) {
  7433. LUIOut(L2,"GetContentsTable: Failed");
  7434. retval=FALSE;
  7435. goto out;
  7436. }
  7437. assert(lpContentsTable != NULL);
  7438. assert(lpRowSet == NULL);
  7439. while((bFound == FALSE) &&(!HR_FAILED(hr = lpContentsTable->QueryRows(IN 1,
  7440. IN 0,
  7441. OUT &lpRowSet)))) {
  7442. if (lpRowSet->cRows) {
  7443. i=0;
  7444. assert(lpRowSet != NULL);
  7445. while(lpRowSet->aRow[0].lpProps[i].ulPropTag != PR_OBJECT_TYPE)
  7446. if (++i >= (int) lpRowSet->aRow[0].cValues)
  7447. {
  7448. LUIOut( L2, "PR_OBJECT_TYPE not found in the row!" );
  7449. retval = FALSE;
  7450. goto out;
  7451. }
  7452. if(lpRowSet->aRow[0].lpProps[i].Value.ul == MAPI_MAILUSER)
  7453. bFound = TRUE;
  7454. else
  7455. {
  7456. FreeProws(lpRowSet);
  7457. lpRowSet = NULL;
  7458. }
  7459. }
  7460. else {
  7461. LUIOut(LFAIL2,"No Mail User Entry found in the PAB");
  7462. retval = FALSE;
  7463. if (lpRowSet) {
  7464. FreeProws(lpRowSet);
  7465. lpRowSet = NULL;
  7466. }
  7467. assert( lpRowSet == NULL);
  7468. goto out;
  7469. }
  7470. }
  7471. // check for QueryRows() errors
  7472. if (HR_FAILED(hr)){
  7473. LUIOut(L2,"QueryRows Failed");
  7474. retval = FALSE;
  7475. goto out;
  7476. }
  7477. if (bFound) {
  7478. i=0;
  7479. assert(lpRowSet != NULL);
  7480. while(lpRowSet->aRow[0].lpProps[i].ulPropTag != PR_ENTRYID)
  7481. if (++i >= (int) lpRowSet->aRow[0].cValues)
  7482. {
  7483. LUIOut( L2, "PR_ENTRYID not found in the row!" );
  7484. retval = FALSE;
  7485. goto out;
  7486. }
  7487. cbEid = lpRowSet->aRow[0].lpProps[i].Value.bin.cb;
  7488. lpEid = (LPENTRYID)lpRowSet->aRow[0].lpProps[i].Value.bin.lpb;
  7489. assert(lpAdrBook != NULL);
  7490. assert(lpUser == NULL);
  7491. hr = lpAdrBook->OpenEntry(cbEid, lpEid, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpUser);
  7492. if (HR_FAILED(hr)) {
  7493. LUIOut(LFAIL2, "OpenEntry with modify flag on first MailUser failed");
  7494. retval = FALSE;
  7495. goto out;
  7496. }
  7497. else LUIOut(LPASS2,"OpenEntry with modify flag on first MailUser passed");
  7498. GetPrivateProfileString("SetProps","Location","",szLocation,SML_BUF,szIniFile);
  7499. GetPrivateProfileString("SetProps","Comment","",szComment,SML_BUF,szIniFile);
  7500. cValues = 2;
  7501. PropValue[0].ulPropTag = PR_OFFICE_LOCATION;
  7502. PropValue[1].ulPropTag = PR_COMMENT;
  7503. PropValue[0].Value.LPSZ = (LPTSTR)szLocation;
  7504. PropValue[1].Value.LPSZ = (LPTSTR)szComment;
  7505. assert(lpUser != NULL);
  7506. hr = lpUser->SetProps(IN cValues,
  7507. IN PropValue,
  7508. IN NULL);
  7509. if (HR_FAILED(hr)) {
  7510. LUIOut(LFAIL2,"SetProps failed for the MailUser");
  7511. retval=FALSE;
  7512. goto out;
  7513. }
  7514. assert(lpUser != NULL);
  7515. hr = lpUser->SaveChanges(IN KEEP_OPEN_READWRITE);
  7516. if (HR_FAILED(hr)) {
  7517. LUIOut(LFAIL2,"SaveChanges failed for SetProps");
  7518. retval=FALSE;
  7519. goto out;
  7520. }
  7521. else LUIOut(LPASS2,"Savechanges passed for the properties on the MailUser in PAB");
  7522. assert(lpUser != NULL);
  7523. assert(lpSPropValue == NULL);
  7524. hr = lpUser->GetProps(
  7525. IN (LPSPropTagArray) &SPTTagArray,
  7526. IN 0,
  7527. OUT &cValues,
  7528. OUT &lpSPropValue);
  7529. if ((HR_FAILED(hr))||(PropError(lpSPropValue->ulPropTag, cValues))) {
  7530. LUIOut( L2,"GetProps on Mail User failed" );
  7531. retval = FALSE;
  7532. goto out;
  7533. }
  7534. else {
  7535. LUIOut(L2,"Verification of Properties set");
  7536. LUIOut(L3,"Entry Name: %s",(lpSPropValue[0]).Value.LPSZ);
  7537. LUIOut(L3,"Location: %s",(lpSPropValue[1]).Value.LPSZ);
  7538. if (lstrcmpi((lpSPropValue[1]).Value.LPSZ, (LPSTR)szLocation))
  7539. retval = FALSE;
  7540. LUIOut(L3,"Comment: %s",(lpSPropValue[2]).Value.LPSZ);
  7541. if (lstrcmpi((lpSPropValue[2]).Value.LPSZ, (LPSTR)szComment))
  7542. retval = FALSE;
  7543. }
  7544. assert(lpUser != NULL);
  7545. hr = lpUser->SaveChanges(IN KEEP_OPEN_READWRITE);
  7546. if (HR_FAILED(hr)) {
  7547. LUIOut(LFAIL2,"SaveChanges, without changes, failed on Mail User in PAB");
  7548. retval=FALSE;
  7549. goto out;
  7550. }
  7551. else LUIOut(LPASS2,"SaveChanges, without changes, passed on Mail User in PAB");
  7552. }
  7553. else {
  7554. LUIOut(LPASS2,"No Mail User Entry found in the PAB to set the properties");
  7555. retval = FALSE;
  7556. }
  7557. out:
  7558. if (lpSPropValue)
  7559. MAPIFreeBuffer(lpSPropValue);
  7560. //if (lpEid)
  7561. // MAPIFreeBuffer(lpEid);
  7562. if (lpContentsTable)
  7563. lpContentsTable->Release();
  7564. if (lpPABCont)
  7565. lpPABCont->Release();
  7566. if (lpEidPAB)
  7567. MAPIFreeBuffer(lpEidPAB);
  7568. if(lpRowSet)
  7569. FreeProws(lpRowSet);
  7570. if(lpUser)
  7571. lpUser->Release();
  7572. if (lpAdrBook)
  7573. lpAdrBook->Release();
  7574. if (lpMAPISession)
  7575. lpMAPISession->Release();
  7576. MAPIUninitialize();
  7577. #endif
  7578. return retval;
  7579. }
  7580. BOOL PABQueryInterface()
  7581. {
  7582. HRESULT hr = hrSuccess;
  7583. int retval=TRUE;
  7584. #ifdef PAB
  7585. int i=0;
  7586. LPMAPISESSION lpMAPISession = NULL;
  7587. LPADRBOOK lpAdrBook = NULL;
  7588. ULONG cbEidPAB = 0;
  7589. LPENTRYID lpEidPAB = NULL;
  7590. LPABCONT lpABCont= NULL, lpABCont2= NULL;
  7591. LPABCONT lpPABCont= NULL,lpPABCont2= NULL;
  7592. LPMAILUSER lpUser=NULL, lpUser2=NULL;
  7593. LPMAPITABLE lpContentsTable = NULL;
  7594. LPSRowSet lpRowSet = NULL;
  7595. ULONG cbEid=0;
  7596. LPENTRYID lpEid=NULL;
  7597. ULONG ulObjType=NULL;
  7598. LUIOut(L1," ");
  7599. LUIOut(L1,"Running QueryInterface");
  7600. LUIOut(L2,"-> Calls QueryInterface on all objects in the PAB");
  7601. LUIOut(L1," ");
  7602. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  7603. LUIOut(LFAIL2,"MapiInitLogon Failed");
  7604. retval = FALSE;
  7605. goto out;
  7606. }
  7607. // Get the IAddrBook
  7608. hr = (lpMAPISession)->OpenAddressBook(
  7609. IN 0, //window handle
  7610. IN NULL, //Interface identifier
  7611. IN 0, //flags
  7612. OUT &lpAdrBook); //pointer to address book object
  7613. if (HR_FAILED(hr)) {
  7614. LUIOut(L2,"OpenAddressBook Failed");
  7615. LUIOut(L3,"Could not open address book for the profile");
  7616. retval=FALSE;
  7617. goto out;
  7618. }
  7619. assert(lpAdrBook != NULL);
  7620. hr = lpAdrBook->OpenEntry(0, NULL, NULL,MAPI_MODIFY,&ulObjType, (LPUNKNOWN *) &lpABCont);
  7621. if (!(retval = LogIt(hr,2, "OpenEntry on AddressBook")))
  7622. goto out;
  7623. if (ulObjType != MAPI_ABCONT) {
  7624. LUIOut(LFAIL2, "Object type is not MAPI_ABCONT");
  7625. retval = FALSE;
  7626. goto out;
  7627. }
  7628. LUIOut(LPASS2, "Object type is MAPI_ABCONT");
  7629. hr = (lpABCont->QueryInterface((REFIID)(IID_IUnknown), (VOID **) &lpABCont2));
  7630. if (!(retval = LogIt(hr,2, "QueryInterface on the Root Container")))
  7631. goto out;
  7632. if(lpABCont2)
  7633. (LPUNKNOWN)(lpABCont2)->Release();
  7634. else {
  7635. LUIOut(LFAIL2, "QueryInterface failed on the Root Container");
  7636. retval = FALSE;
  7637. }
  7638. lpABCont2 = NULL;
  7639. if(!OpenPABID(IN lpAdrBook, OUT &cbEidPAB,
  7640. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType))
  7641. {
  7642. LUIOut(L2,"OpenPABID Failed");
  7643. LUIOut(L3,"Could not Open PAB");
  7644. retval=FALSE;
  7645. goto out;
  7646. }
  7647. hr = (lpPABCont->QueryInterface((REFIID)(IID_IUnknown), (VOID **) &lpPABCont2));
  7648. if (!(retval = LogIt(hr,2, "QueryInterface on the PAB Container")))
  7649. goto out;
  7650. if(lpPABCont2)
  7651. (LPUNKNOWN)(lpPABCont2)->Release();
  7652. else {
  7653. LUIOut(LFAIL2, "QueryInterface failed on the Root Container");
  7654. retval = FALSE;
  7655. }
  7656. lpPABCont2 = NULL;
  7657. // Now open the PAB and get a user and do QueryInterface on the User
  7658. hr = lpPABCont->GetContentsTable( IN 0, //Flags
  7659. OUT &lpContentsTable);
  7660. if (HR_FAILED(hr)) {
  7661. LUIOut(LFAIL2,"GetContentsTable: Failed");
  7662. retval=FALSE;
  7663. goto out;
  7664. }
  7665. assert(lpContentsTable != NULL);
  7666. assert(lpRowSet == NULL);
  7667. hr = lpContentsTable->QueryRows(1, 0, OUT &lpRowSet);
  7668. if (!(retval = LogIt(hr,2, "QueryRows on the PAB Container")))
  7669. goto out;
  7670. if (lpRowSet->cRows) {
  7671. i=0;
  7672. while(lpRowSet->aRow[0].lpProps[i].ulPropTag != PR_ENTRYID )
  7673. if (++i >= (int) lpRowSet->aRow[0].cValues)
  7674. {
  7675. LUIOut(LFAIL2,"PR_ENTRYID not found in the row!" );
  7676. retval = FALSE;
  7677. goto out;
  7678. }
  7679. cbEid = lpRowSet->aRow[0].lpProps[i].Value.bin.cb;
  7680. lpEid = (LPENTRYID)lpRowSet->aRow[0].lpProps[i].Value.bin.lpb;
  7681. hr = lpPABCont->OpenEntry(cbEid, lpEid, NULL, 0, &ulObjType,(LPUNKNOWN *)&lpUser);
  7682. if (!(retval = LogIt(hr,2, "OpenEntry on EntryID for PAB Entry")))
  7683. goto out;
  7684. FreeProws(lpRowSet);
  7685. lpRowSet = NULL;
  7686. hr = lpUser->QueryInterface(IID_IUnknown, (VOID **) &lpUser2);
  7687. if (!(retval = LogIt(hr,2, "QueryInterface on an Entry in PAB")))
  7688. goto out;
  7689. if(lpUser2)
  7690. (LPUNKNOWN)(lpUser2)->Release();
  7691. else {
  7692. LUIOut(LFAIL2, "QueryInterface failed on an Entry in PAB");
  7693. retval = FALSE;
  7694. }
  7695. lpUser2 = NULL;
  7696. }
  7697. else {
  7698. LUIOut(LFAIL2, "No Entries found in the PAB");
  7699. retval = FALSE;
  7700. goto out;
  7701. }
  7702. out:
  7703. if (lpABCont)
  7704. lpABCont->Release();
  7705. if (lpABCont2)
  7706. lpABCont2->Release();
  7707. if (lpPABCont)
  7708. lpPABCont->Release();
  7709. if (lpPABCont2)
  7710. lpPABCont2->Release();
  7711. if (lpEid)
  7712. MAPIFreeBuffer(lpEid);
  7713. if (lpContentsTable)
  7714. lpContentsTable->Release();
  7715. if (lpEidPAB)
  7716. MAPIFreeBuffer(lpEidPAB);
  7717. if(lpRowSet)
  7718. FreeProws(lpRowSet);
  7719. if(lpUser)
  7720. lpUser->Release();
  7721. if(lpUser2)
  7722. lpUser2->Release();
  7723. if (lpAdrBook)
  7724. lpAdrBook->Release();
  7725. if (lpMAPISession)
  7726. lpMAPISession->Release();
  7727. MAPIUninitialize();
  7728. #endif
  7729. return retval;
  7730. }
  7731. BOOL PABPrepareRecips()
  7732. {
  7733. HRESULT hr = hrSuccess;
  7734. int retval=TRUE;
  7735. #ifdef PAB
  7736. LPMAPISESSION lpMAPISession = NULL;
  7737. LPADRBOOK lpAdrBook = NULL;
  7738. LPABCONT lpPABCont= NULL;
  7739. ULONG cEntries=0;
  7740. LPADRLIST lpAdrList = NULL;
  7741. char EntProp[10][BIG_BUF];
  7742. ULONG cbEidPAB = 0;
  7743. LPENTRYID lpEidPAB = NULL;
  7744. LPSPropValue lpSPropValueAddress = NULL;
  7745. LPSPropTagArray lpPropTagArray = NULL;
  7746. LPMAILUSER lpAddress = NULL;
  7747. SPropValue PropValue[3] = {0};
  7748. SizedSPropTagArray(1,SPTArrayAddress) = {1, {PR_DEF_CREATE_MAILUSER} };
  7749. char szEntryTag[SML_BUF],EntryBuf[MAX_BUF];
  7750. int i = 0,j=0, cPropCount=0;
  7751. ULONG cbEid=0, cbUserEid=0, cValues;
  7752. LPENTRYID lpEid = NULL, lpUserEid = NULL;
  7753. LUIOut(L1," ");
  7754. LUIOut(L1,"Running PrepareRecips");
  7755. LUIOut(L2,"-> Does Prepare Recipients Test on PAB");
  7756. LUIOut(L1," ");
  7757. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  7758. LUIOut(LFAIL2,"MapiInitLogon Failed");
  7759. retval = FALSE;
  7760. goto out;
  7761. }
  7762. // Get the IAddrBook
  7763. hr = (lpMAPISession)->OpenAddressBook(
  7764. IN 0, //window handle
  7765. IN NULL, //Interface identifier
  7766. IN 0, //flags
  7767. OUT &lpAdrBook); //pointer to address book object
  7768. if (HR_FAILED(hr)) {
  7769. LUIOut(LFAIL2,"OpenAddressBook Failed");
  7770. LUIOut(L3,"Could not open address book for the profile");
  7771. retval=FALSE;
  7772. goto out;
  7773. }
  7774. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  7775. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType);
  7776. if (HR_FAILED(hr)) {
  7777. LUIOut(L2,"OpenPABID Failed");
  7778. LUIOut(L3,"Could not Open PAB");
  7779. retval=FALSE;
  7780. goto out;
  7781. }
  7782. LUIOut(L2,"Create a User Entry in PAB");
  7783. hr = lpPABCont->GetProps( IN (LPSPropTagArray) &SPTArrayAddress,
  7784. IN 0, //Flags
  7785. OUT &cValues,
  7786. OUT &lpSPropValueAddress);
  7787. if ((HR_FAILED(hr))||(PropError(lpSPropValueAddress->ulPropTag, cValues))) {
  7788. LUIOut(L3,"GetProps failed for Default template");
  7789. retval=FALSE;
  7790. goto out;
  7791. }
  7792. cbUserEid = lpSPropValueAddress->Value.bin.cb;
  7793. if ( !MAPIAllocateBuffer(cbUserEid, (LPVOID *)&lpUserEid)) {
  7794. CopyMemory(lpUserEid, (LPENTRYID) lpSPropValueAddress->Value.bin.lpb, cbUserEid);
  7795. }
  7796. else {
  7797. retval = FALSE;
  7798. LUIOut(LFAIL3," MAPIAllocateBuffer failed");
  7799. goto out;
  7800. }
  7801. // The returned value of PR_DEF_CREATE_MAILUSER is an
  7802. // EntryID which one can pass to CreateEntry
  7803. //
  7804. hr = lpPABCont->CreateEntry(
  7805. IN lpSPropValueAddress->Value.bin.cb, //Template cbEid
  7806. IN (LPENTRYID) lpSPropValueAddress->Value.bin.lpb, //Template lpEid
  7807. IN 0,
  7808. OUT (LPMAPIPROP *) &lpAddress);
  7809. if (HR_FAILED(hr)) {
  7810. LUIOut(LFAIL3,"CreateEntry failed for PR_DEF_CREATE_MAILUSER");
  7811. retval=FALSE;
  7812. goto out;
  7813. }
  7814. //
  7815. // Then set the properties
  7816. //
  7817. PropValue[0].ulPropTag = PR_DISPLAY_NAME;
  7818. PropValue[1].ulPropTag = PR_ADDRTYPE;
  7819. PropValue[2].ulPropTag = PR_EMAIL_ADDRESS;
  7820. cValues = 3; //# of props we are setting
  7821. lstrcpy((LPSTR)szEntryTag,"CreateUserAddress");
  7822. // Addresses are comma delimited and enclosed in quotes
  7823. GetPrivateProfileString("PrepareRecips",szEntryTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  7824. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  7825. LUIOut(L3,"Entry to Create: %s",EntProp[0]);
  7826. for (i=0; i<(int)cValues;i++)
  7827. PropValue[i].Value.LPSZ = (LPTSTR)EntProp[i];
  7828. hr = lpAddress->SetProps(IN cValues,
  7829. IN PropValue,
  7830. IN NULL);
  7831. if (HR_FAILED(hr)) {
  7832. LUIOut(L3,"SetProps failed for %s",PropValue[0].Value.LPSZ);
  7833. retval=FALSE;
  7834. goto out;
  7835. }
  7836. hr = lpAddress->SaveChanges(IN KEEP_OPEN_READWRITE); //flags
  7837. if (HR_FAILED(hr)) {
  7838. LUIOut(L3,"SaveChanges failed for SetProps");
  7839. retval=FALSE;
  7840. goto out;
  7841. }
  7842. else LUIOut(LPASS3,"Entry Added to PAB");
  7843. LUIOut(L2,"Create a OneOff Entry in PAB");
  7844. // Create a oneoff user
  7845. cValues = 3;
  7846. lstrcpy((LPSTR)szEntryTag,"CreateOneOffAddress");
  7847. GetPrivateProfileString("PrepareRecips",szEntryTag,"",EntryBuf,MAX_BUF,INIFILENAME);
  7848. GetPropsFromIniBufEntry(EntryBuf,cValues,EntProp);
  7849. LUIOut(L3,"Entry to Create: %s",EntProp[0]);
  7850. hr = lpAdrBook->CreateOneOff(EntProp[0],EntProp[1],EntProp[2],NULL,&cbEid,&lpEid);
  7851. if (HR_FAILED(hr)) {
  7852. LUIOut(LFAIL3,"CreateOneOff");
  7853. retval=FALSE;
  7854. goto out;
  7855. }
  7856. else LUIOut(LPASS3,"CreateOneOff");
  7857. LUIOut(L2,"Call PrepareRecips on these two entries in the PAB");
  7858. cEntries = 2;
  7859. MAPIAllocateBuffer(CbNewADRLIST(cEntries), (LPVOID *) &lpAdrList );
  7860. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[0].rgPropVals));
  7861. MAPIAllocateBuffer(sizeof(SPropValue), (LPVOID *) &(lpAdrList->aEntries[1].rgPropVals));
  7862. lpAdrList->cEntries = cEntries;
  7863. lpAdrList->aEntries[0].cValues = 1;
  7864. lpAdrList->aEntries[0].rgPropVals->ulPropTag = PR_ENTRYID;
  7865. lpAdrList->aEntries[0].rgPropVals->dwAlignPad = 0;
  7866. lpAdrList->aEntries[0].rgPropVals->Value.bin.cb = cbUserEid;
  7867. lpAdrList->aEntries[0].rgPropVals->Value.bin.lpb = (LPBYTE) lpUserEid;
  7868. lpAdrList->aEntries[1].cValues = 1;
  7869. lpAdrList->aEntries[1].rgPropVals->ulPropTag = PR_ENTRYID;
  7870. lpAdrList->aEntries[1].rgPropVals->dwAlignPad = 0;
  7871. lpAdrList->aEntries[1].rgPropVals->Value.bin.cb = cbEid;
  7872. lpAdrList->aEntries[1].rgPropVals->Value.bin.lpb = (LPBYTE) lpEid;
  7873. cPropCount = 8;
  7874. MAPIAllocateBuffer( CbNewSPropTagArray(cPropCount), (void **)&lpPropTagArray );
  7875. lpPropTagArray->cValues = cPropCount;
  7876. lpPropTagArray->aulPropTag[0] = PR_DISPLAY_NAME;
  7877. lpPropTagArray->aulPropTag[1] = PR_OBJECT_TYPE;
  7878. lpPropTagArray->aulPropTag[2] = PR_ADDRTYPE;
  7879. lpPropTagArray->aulPropTag[3] = PR_EMAIL_ADDRESS;
  7880. lpPropTagArray->aulPropTag[4] = PR_DISPLAY_TYPE;
  7881. lpPropTagArray->aulPropTag[5] = PR_CALLBACK_TELEPHONE_NUMBER;
  7882. lpPropTagArray->aulPropTag[6] = PR_COMMENT;
  7883. lpPropTagArray->aulPropTag[7] = PR_OFFICE_LOCATION;
  7884. if( lpAdrBook->PrepareRecips( 0, lpPropTagArray, lpAdrList ) )
  7885. {
  7886. LUIOut(LFAIL3, "PrepareRecips failed" );
  7887. retval = FALSE;
  7888. goto out;
  7889. }
  7890. else LUIOut(LPASS3, "PrepareRecips passed" );
  7891. if(lpAdrList->cEntries == 0 )
  7892. {
  7893. LUIOut(LFAIL3, "No entries were prepared" );
  7894. retval = FALSE;
  7895. goto out;
  7896. }
  7897. LUIOut(L2,"Verify the returned Properties");
  7898. for ( i = 0; i < (int) cEntries; i++ ) {
  7899. LUIOut(L3,"Entry #: %d",i);
  7900. if (lpAdrList->aEntries[i].cValues != (ULONG)(cPropCount + 1)) {
  7901. LUIOut(LFAIL4, "Number of returned properties is incorrect");
  7902. retval = FALSE;
  7903. goto out;
  7904. }
  7905. else LUIOut(LPASS4, "Number of returned properties is correct");
  7906. for ( j = 0; j < cPropCount; j++ ) {
  7907. if ( PROP_ID(lpAdrList->aEntries[i].rgPropVals[j].ulPropTag) !=
  7908. PROP_ID(lpPropTagArray->aulPropTag[j])) {
  7909. LUIOut(LFAIL4, "Property IDs do not match in the returned data");
  7910. retval = FALSE;
  7911. goto out;
  7912. }
  7913. }
  7914. LUIOut(LPASS4, "All Property IDs match in the returned data");
  7915. if (lpAdrList->aEntries[i].rgPropVals[j].ulPropTag != PR_ENTRYID ) {
  7916. LUIOut(LFAIL4, "Last Property Tag != PR_ENTRYID");
  7917. retval = FALSE;
  7918. goto out;
  7919. } else LUIOut(LPASS4, "Last Property Tag == PR_ENTRYID");
  7920. }
  7921. out:
  7922. if (cEntries > 0)
  7923. for (i=0;i<(int)cEntries; i++) {
  7924. MAPIFreeBuffer( lpAdrList->aEntries[i].rgPropVals );
  7925. }
  7926. if (lpAdrList) {
  7927. MAPIFreeBuffer( lpAdrList );
  7928. lpAdrList = NULL;
  7929. }
  7930. if (lpPABCont)
  7931. lpPABCont->Release();
  7932. if (lpEidPAB)
  7933. MAPIFreeBuffer(lpEidPAB);
  7934. if (lpSPropValueAddress)
  7935. MAPIFreeBuffer(lpSPropValueAddress);
  7936. if (lpEid)
  7937. MAPIFreeBuffer(lpEid);
  7938. if (lpUserEid)
  7939. MAPIFreeBuffer(lpUserEid);
  7940. if (lpAddress)
  7941. lpAddress->Release();
  7942. if (lpPropTagArray)
  7943. MAPIFreeBuffer(lpPropTagArray);
  7944. if (lpAdrBook)
  7945. lpAdrBook->Release();
  7946. if (lpMAPISession)
  7947. lpMAPISession->Release();
  7948. MAPIUninitialize();
  7949. #endif
  7950. return retval;
  7951. }
  7952. BOOL PABCopyEntries()
  7953. {
  7954. HRESULT hr = hrSuccess;
  7955. int retval=TRUE;
  7956. #ifdef PAB
  7957. SizedSPropTagArray(2,SPTTagArray) = {2, {PR_DISPLAY_NAME, PR_ENTRYID } };
  7958. LPMAPISESSION lpMAPISession = NULL;
  7959. LPADRBOOK lpAdrBook = NULL;
  7960. LPABCONT lpPABCont= NULL,lpABCont = NULL, lpABPCont = NULL;
  7961. LPMAPITABLE lpABTable = NULL,lpABPTable= NULL;
  7962. LPSRowSet lpRowSet = NULL, lpPRowSet = NULL;
  7963. ULONG cbEid = 0, cbEidPAB = 0;
  7964. LPENTRYID lpEid = NULL, lpEidPAB = NULL;
  7965. ULONG ulObjType=NULL, ulSeed=0,ulMaxEntries = 0;
  7966. ULONG ulPRowCount=0, ulTotalCount=0;
  7967. int idx=0;
  7968. LONG lSeekRow=0,lRowsSeeked=0,lPRowsSeeked=0,lPSeekRow=0;
  7969. LPENTRYLIST lpEntries= NULL;
  7970. LUIOut(L1," ");
  7971. LUIOut(L1,"Running CopyEntries");
  7972. LUIOut(L2,"-> Copies Entries from other Providers into PAB");
  7973. LUIOut(L1," ");
  7974. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  7975. LUIOut(LFAIL2,"MapiInitLogon Failed");
  7976. retval = FALSE;
  7977. goto out;
  7978. }
  7979. // Get the IAddrBook
  7980. hr = (lpMAPISession)->OpenAddressBook(
  7981. IN 0, //window handle
  7982. IN NULL, //Interface identifier
  7983. IN 0, //flags
  7984. OUT &lpAdrBook); //pointer to address book object
  7985. if (HR_FAILED(hr)) {
  7986. LUIOut(LFAIL2,"OpenAddressBook Failed");
  7987. LUIOut(L3,"Could not open address book for the profile");
  7988. retval=FALSE;
  7989. goto out;
  7990. }
  7991. hr = OpenPABID( IN lpAdrBook, OUT &cbEidPAB,
  7992. OUT &lpEidPAB,OUT &lpPABCont, OUT &ulObjType);
  7993. if (HR_FAILED(hr)) {
  7994. LUIOut(L2,"OpenPABID Failed");
  7995. LUIOut(L3,"Could not Open PAB");
  7996. retval=FALSE;
  7997. goto out;
  7998. }
  7999. assert(lpAdrBook != NULL);
  8000. hr = lpAdrBook->OpenEntry(0, NULL, NULL,0,&ulObjType, (LPUNKNOWN *) &lpABCont);
  8001. if (!(retval = LogIt(hr,2, "OpenEntry on Root Container AddressBook")))
  8002. goto out;
  8003. if (ulObjType != MAPI_ABCONT) {
  8004. LUIOut(LFAIL2, "Object type is not MAPI_ABCONT");
  8005. retval = FALSE;
  8006. goto out;
  8007. }
  8008. LUIOut(LPASS2, "Object type is MAPI_ABCONT");
  8009. hr = lpABCont->GetHierarchyTable(CONVENIENT_DEPTH,&lpABTable);
  8010. // hr = lpABCont->GetHierarchyTable(0,&lpABTable);
  8011. if (!(retval = LogIt(hr,2, "GetHierarchyTable on Root Container")))
  8012. goto out;
  8013. hr = lpABTable->GetRowCount(0,&ulTotalCount);
  8014. if (!(retval = LogIt(hr,2, "GetRowCount on Root Container")))
  8015. goto out;
  8016. if (ulTotalCount == 0)
  8017. {
  8018. LUIOut(LFAIL2,"No rows in Root AddressBook table.");
  8019. retval = FALSE;
  8020. goto out;
  8021. }
  8022. hr = lpABTable->SetColumns(IN (LPSPropTagArray) &SPTTagArray,
  8023. IN 0);
  8024. if (!(retval = LogIt(hr,2, "SetColumns")))
  8025. goto out;
  8026. ulSeed = (unsigned)time( NULL );
  8027. //LUIOut(LPASS3, "Random seed = %lu", ulSeed );
  8028. srand(ulSeed);
  8029. ulMaxEntries = GetPrivateProfileInt("CopyEntries","ulMaxEntries", 3, INIFILENAME);
  8030. for(idx = 0; (idx < ((int)ulTotalCount) && (idx < (int) ulMaxEntries)); ++idx)
  8031. {
  8032. /* Generate a random number */
  8033. /* Seek to that row */
  8034. lSeekRow = idx;
  8035. hr = lpABTable->SeekRow(BOOKMARK_BEGINNING, (LONG)lSeekRow,
  8036. &lRowsSeeked);
  8037. if (!(retval = LogIt(hr,2, "SeekRow on Root Address Book Table")))
  8038. goto out;
  8039. hr = lpABTable->QueryRows(1, TBL_NOADVANCE, &lpRowSet);
  8040. if (!(retval = LogIt(hr,2, "QueryRows on Root Address Book Table")))
  8041. goto out;
  8042. LUIOut(L3," # %d: Provider is %s",idx+1,lpRowSet->aRow[0].lpProps[0].Value.LPSZ);
  8043. cbEid = lpRowSet->aRow[0].lpProps[1].Value.bin.cb;
  8044. lpEid = (LPENTRYID)lpRowSet->aRow[0].lpProps[1].Value.bin.lpb;
  8045. /* Open the entry */
  8046. hr = lpAdrBook->OpenEntry(cbEid,lpEid, NULL, 0, &ulObjType,
  8047. OUT (LPUNKNOWN *) &lpABPCont);
  8048. if (!(retval = LogIt(hr,4, "OpenEntry on an entry in the hierarchy table")))
  8049. goto out;
  8050. hr = lpABPCont->GetContentsTable(0, &lpABPTable);
  8051. if (HR_FAILED(hr))
  8052. goto directory;
  8053. LUIOut(LPASS4,"GetContentsTable");
  8054. hr = lpABPTable->GetRowCount(0, &ulPRowCount);
  8055. if (!(retval = LogIt(hr,4, "GetRowCount on Provider table")))
  8056. goto out;
  8057. if(ulPRowCount > 0)
  8058. {
  8059. hr = lpABPTable->SetColumns(IN (LPSPropTagArray) &SPTTagArray, 0);
  8060. if (!(retval = LogIt(hr,4, "SetColumns on Provider table")))
  8061. goto out;
  8062. lPSeekRow = (rand() % ulPRowCount);
  8063. hr = lpABPTable->SeekRow(BOOKMARK_BEGINNING, (LONG)lPSeekRow,
  8064. &lPRowsSeeked);
  8065. if (!(retval = LogIt(hr,4, "SeekRows on Provider table")))
  8066. goto out;
  8067. hr = lpABPTable->QueryRows(1, TBL_NOADVANCE, &lpPRowSet);
  8068. if (!(retval = LogIt(hr,4, "QueryRows on Provider table")))
  8069. goto out;
  8070. if(!lpPRowSet->cRows)
  8071. goto directory;
  8072. else
  8073. {
  8074. LUIOut(L3,"Entry to Copy is %s",lpPRowSet->aRow[0].lpProps[0].Value.LPSZ);
  8075. /* Copy the entry */
  8076. int temp = sizeof(ENTRYLIST);
  8077. MAPIAllocateBuffer(sizeof(ENTRYLIST),(LPVOID *)&lpEntries);
  8078. if (lpEntries ) {
  8079. lpEntries->cValues = 1;
  8080. lpEntries->lpbin = NULL;
  8081. MAPIAllocateBuffer((sizeof(SBinary)*lpEntries->cValues),
  8082. (LPVOID *) &(lpEntries->lpbin));
  8083. if (lpEntries->lpbin) {
  8084. lpEntries->lpbin->cb = lpPRowSet->aRow[0].lpProps[1].Value.bin.cb;
  8085. lpEntries->lpbin->lpb = NULL;
  8086. MAPIAllocateBuffer(lpPRowSet->aRow[0].lpProps[1].Value.bin.cb,
  8087. (LPVOID *)&(lpEntries->lpbin->lpb));
  8088. if (lpEntries->lpbin->lpb) {
  8089. CopyMemory(lpEntries->lpbin->lpb,
  8090. lpPRowSet->aRow[0].lpProps[1].Value.bin.lpb,
  8091. (size_t)lpPRowSet->aRow[0].lpProps[1].Value.bin.cb);
  8092. }
  8093. else {
  8094. LUIOut(LFAIL3,"MAPIAllocateBuffer" );
  8095. retval = FALSE;
  8096. goto out;
  8097. }
  8098. }
  8099. else {
  8100. LUIOut(LFAIL3,"MAPIAllocateBuffer" );
  8101. retval = FALSE;
  8102. goto out;
  8103. }
  8104. }
  8105. else {
  8106. LUIOut(LFAIL3,"MAPIAllocateBuffer" );
  8107. retval = FALSE;
  8108. goto out;
  8109. }
  8110. /* Add to PAB */
  8111. hr = lpPABCont->CopyEntries(lpEntries, (ULONG)GetActiveWindow(), NULL, CREATE_CHECK_DUP_STRICT);
  8112. if (HR_FAILED(hr))
  8113. {
  8114. LUIOut(LFAIL3,"User could not be added to the PAB." );
  8115. retval = FALSE;
  8116. goto out;
  8117. }
  8118. LUIOut(LPASS3,"User was added to the PAB");
  8119. /* Free the EntryList */
  8120. MAPIFreeBuffer(lpEntries->lpbin->lpb);
  8121. lpEntries->lpbin->lpb = NULL;
  8122. MAPIFreeBuffer(lpEntries->lpbin);
  8123. lpEntries->lpbin = NULL;
  8124. MAPIFreeBuffer(lpEntries);
  8125. lpEntries = NULL;
  8126. /* Free Row */
  8127. if (lpPRowSet) {
  8128. FreeProws(lpPRowSet);
  8129. lpPRowSet = NULL;
  8130. }
  8131. }
  8132. }
  8133. else //if (lstrcmpi(lpRowSet->aRow[0].lpProps[0].Value.LPSZ,"Personal Address Book"))
  8134. directory:
  8135. {
  8136. //--idx;
  8137. /* We want to decrement our counter so we dont add x-1. */
  8138. LUIOut(L3, "Nothing to add. No Rows in the Provider");
  8139. }
  8140. if(lpABPTable) {
  8141. lpABPTable->Release();
  8142. lpABPTable = NULL;
  8143. }
  8144. if(lpABPCont) {
  8145. lpABPCont->Release();
  8146. lpABPCont = NULL;
  8147. }
  8148. if (lpRowSet) {
  8149. FreeProws(lpRowSet);
  8150. lpRowSet = NULL;
  8151. }
  8152. }
  8153. out:
  8154. if (lpEntries) {
  8155. if (lpEntries->lpbin) {
  8156. if (lpEntries->lpbin->lpb)
  8157. MAPIFreeBuffer(lpEntries->lpbin->lpb);
  8158. MAPIFreeBuffer(lpEntries->lpbin);
  8159. }
  8160. MAPIFreeBuffer(lpEntries);
  8161. lpEntries->lpbin = NULL;
  8162. }
  8163. if(lpRowSet)
  8164. FreeProws(lpRowSet);
  8165. if(lpPRowSet)
  8166. FreeProws(lpPRowSet);
  8167. if (lpPABCont)
  8168. lpPABCont->Release();
  8169. if (lpABCont)
  8170. lpABCont->Release();
  8171. if (lpABPCont)
  8172. lpABPCont->Release();
  8173. if (lpEidPAB)
  8174. MAPIFreeBuffer(lpEidPAB);
  8175. if (lpEid)
  8176. MAPIFreeBuffer(lpEid);
  8177. if (lpABTable)
  8178. lpABTable->Release();
  8179. if (lpABPTable)
  8180. lpABPTable->Release();
  8181. //if (lpUserEid)
  8182. // MAPIFreeBuffer(lpUserEid);
  8183. if (lpAdrBook)
  8184. lpAdrBook->Release();
  8185. if (lpMAPISession)
  8186. lpMAPISession->Release();
  8187. MAPIUninitialize();
  8188. #endif
  8189. return retval;
  8190. }
  8191. BOOL PABRunBVT()
  8192. {
  8193. LUIOut(L1,"");
  8194. LUIOut(L1,"Running BVT");
  8195. int retval = TRUE;
  8196. //First Clear the PAB
  8197. if (ClearPab(0)) {
  8198. LUIOut(L2,"Clearing PAB");
  8199. LUIOut(LPASS3,"Delete All Entries");
  8200. }
  8201. else {
  8202. LUIOut(LFAIL3,"Delete All Entries: %d");
  8203. retval = FALSE;
  8204. }
  8205. // Create Entries in the PAB
  8206. if (PabCreateEntry()) {
  8207. LUIOut(L2,"Creating Entries in the PAB");
  8208. LUIOut(LPASS3,"Create Entries");
  8209. }
  8210. else {
  8211. LUIOut(LFAIL3,"Create Entries");
  8212. retval = FALSE;
  8213. }
  8214. //Enuerate the Entries in PAB
  8215. if (PabEnumerateAll()) {
  8216. LUIOut(L2,"Enumerate All Entries in the PAB");
  8217. LUIOut(LPASS3,"Enumerate All");
  8218. }
  8219. else {
  8220. LUIOut(LFAIL3,"Enumerate All");
  8221. retval = FALSE;
  8222. }
  8223. //Delete Entries in PAB
  8224. if (PabDeleteEntry()) {
  8225. LUIOut(L2,"Delete specified Entries");
  8226. LUIOut(LPASS3,"DeleteEntries");
  8227. }
  8228. else {
  8229. LUIOut(LFAIL3,"DeleteEntries");
  8230. retval = FALSE;
  8231. }
  8232. // Create a OneOff Entry
  8233. if (CreateOneOff()) {
  8234. LUIOut(L2,"Create a OneOff Entry in the PAB");
  8235. LUIOut(LPASS3,"CreateOneOff");
  8236. }
  8237. else {
  8238. LUIOut(LFAIL3,"CreateOneOff");
  8239. retval = FALSE;
  8240. }
  8241. // Do a SetProps on a Mail User
  8242. if (PABSetProps()) {
  8243. LUIOut(L2,"SetProps on a Mail User Entry in the PAB");
  8244. LUIOut(LPASS3,"SetProps");
  8245. }
  8246. else {
  8247. LUIOut(LFAIL3,"SetProps");
  8248. retval = FALSE;
  8249. }
  8250. // CopyEntries from other providers
  8251. if (PABCopyEntries()) {
  8252. LUIOut(L2,"CopyEntries");
  8253. LUIOut(LPASS3,"CopyEntries");
  8254. }
  8255. else {
  8256. LUIOut(LFAIL3,"CopyEntries");
  8257. retval = FALSE;
  8258. }
  8259. // Resolve Names
  8260. if (PABResolveName()) {
  8261. LUIOut(L2,"ResolveName");
  8262. LUIOut(LPASS3,"ResolveName");
  8263. }
  8264. else {
  8265. LUIOut(LFAIL3,"ResolveName");
  8266. retval = FALSE;
  8267. }
  8268. // Query Interface
  8269. if (PABQueryInterface()) {
  8270. LUIOut(L2,"ResolveName");
  8271. LUIOut(LPASS3,"QueryInterface");
  8272. }
  8273. else {
  8274. LUIOut(LFAIL3,"QueryInterface");
  8275. retval = FALSE;
  8276. }
  8277. // PrepareRecips
  8278. if (PABPrepareRecips()) {
  8279. LUIOut(L2,"PrepareRecips");
  8280. LUIOut(LPASS3,"PrepareRecips");
  8281. }
  8282. else {
  8283. LUIOut(LFAIL3,"PrepareRecips");
  8284. retval = FALSE;
  8285. }
  8286. // Delete Users Only
  8287. if (ClearPab(1)) {
  8288. LUIOut(L2,"Delete Mail Users Only");
  8289. LUIOut(LPASS3,"DeleteUsers");
  8290. }
  8291. else {
  8292. LUIOut(LFAIL3,"DeleteUsers");
  8293. retval = FALSE;
  8294. }
  8295. return retval;
  8296. }
  8297. INT_PTR CALLBACK SetIniFile(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  8298. {
  8299. static char szNewIniFile[BIG_BUF];
  8300. switch(msg)
  8301. {
  8302. case WM_INITDIALOG:
  8303. SendDlgItemMessage(hWndDlg,IDC_EDIT,WM_SETTEXT, 0,(LPARAM)(LPCTSTR)szIniFile);
  8304. SetFocus(GetDlgItem(hWndDlg,IDC_EDIT));
  8305. return FALSE;
  8306. case WM_COMMAND:
  8307. switch(LOWORD(wParam))
  8308. {
  8309. case IDOK:
  8310. SendDlgItemMessage(hWndDlg,IDC_EDIT,WM_GETTEXT, BIG_BUF,(LPARAM)szNewIniFile);
  8311. if (lstrcmpi(szNewIniFile,szIniFile))
  8312. lstrcpy(szIniFile,szNewIniFile);
  8313. EndDialog(hWndDlg,TRUE);
  8314. return TRUE;
  8315. case IDCANCEL:
  8316. EndDialog(hWndDlg,FALSE);
  8317. return TRUE;
  8318. }
  8319. break;
  8320. default:
  8321. return FALSE;
  8322. }
  8323. return FALSE;
  8324. }
  8325. BOOL VerifyBuffer(DWORD ** lppvBufPtr, DWORD dwBufferSize)
  8326. {
  8327. DWORD *lpdwWrkPtr = *lppvBufPtr;
  8328. DWORD counter, cells, part, cellsize;
  8329. BYTE *lpbPart;
  8330. // Walk through the allocated buffer's BUFFERSIZE/sizeof(DWORD) cells
  8331. // and fill each DWORD with a pattern (the # of the cell). Then walk
  8332. // the buffer and verify each pattern.
  8333. cellsize = sizeof(DWORD);
  8334. LUIOut(L3,"Writing test patterns to all cells in the buffer.");
  8335. cells = (dwBufferSize/cellsize); // How many DWORD cells in the buffer?
  8336. part= (ULONG)fmod((double)dwBufferSize, (double)cellsize); // Is there a remaining section?
  8337. // Write the pattern to memory for the 'cells' portion of the buffer
  8338. for(counter=0; counter < cells; counter++, lpdwWrkPtr++) {
  8339. *lpdwWrkPtr = counter;
  8340. }
  8341. lpbPart = (BYTE*)lpdwWrkPtr;
  8342. // Write the pattern to memory for the 'part' leftover portion of the buffer
  8343. for (counter = 0; counter < part; counter++, lpbPart++) {
  8344. *lpbPart = PATTERN;
  8345. }
  8346. lpdwWrkPtr = *lppvBufPtr; //reset work pointer to beginning of buffer
  8347. LUIOut(L3,"Verifying test patterns for %u %u-byte cells in the buffer.",
  8348. cells, cellsize);
  8349. // Verify the pattern in memory for the 'cells' portion of the buffer
  8350. for(counter=0; counter < cells; counter++, lpdwWrkPtr++) {
  8351. if (*lpdwWrkPtr != counter) {
  8352. LUIOut(L3,"Verification Failed: Cell %u, expected %u but found %u",
  8353. counter, counter, *lpdwWrkPtr);
  8354. goto bailout;
  8355. }
  8356. }
  8357. LUIOut(L3,"Verified %u cells succesfully", counter);
  8358. LUIOut(L3,"Verifying test patterns for the remaining %u bytes in the buffer.",
  8359. part);
  8360. // Verify the pattern in memory for the 'part' leftover portion of the buffer
  8361. lpbPart = (BYTE*)lpdwWrkPtr;
  8362. for(counter=0; counter < part; counter++, lpdwWrkPtr++) {
  8363. if (*lpbPart != PATTERN) {
  8364. LUIOut(L3,"Verification Failed: Byte %u, expected %u but found %u",
  8365. counter, PATTERN, *lpdwWrkPtr);
  8366. goto bailout;
  8367. }
  8368. }
  8369. LUIOut(L3,"Verified remaining buffer succesfully");
  8370. return TRUE;
  8371. bailout: //verification failed, so I'm outa here!
  8372. return FALSE;
  8373. }
  8374. BOOL GetAB(OUT LPADRBOOK* lppAdrBook)
  8375. {
  8376. HRESULT hr;
  8377. BOOL retval = TRUE;
  8378. //### token to find pab/wab dependencies
  8379. #ifdef WAB
  8380. // WAB
  8381. LPVOID lpReserved = NULL;
  8382. DWORD dwReserved = 0;
  8383. WAB_PARAM WP;
  8384. ZeroMemory((void *)&WP, sizeof(WAB_PARAM));
  8385. WP.cbSize=sizeof(WAB_PARAM);
  8386. LUIOut(L1, "[ Using the WAB ]");
  8387. lpWABObject=NULL;
  8388. // hr = WABOpen(lppAdrBook, &lpWABObject, &WP, dwReserved);
  8389. hr = WABOpen(lppAdrBook, &lpWABObject, (WAB_PARAM*)lpReserved, dwReserved);
  8390. if (HR_FAILED(hr)) {
  8391. LUIOut(L2,"WABOpen FAILED with hr = 0x%x", hr);
  8392. retval=FALSE;
  8393. goto out;
  8394. }
  8395. // store the ab pointer in a global variable, temporary kludge to workaround
  8396. // the mulitple wabopen/release bug
  8397. glbllpAdrBook = *lppAdrBook;
  8398. #endif
  8399. #ifdef PAB
  8400. // MAPI-PAB
  8401. LUIOut(L1, "[ Using the MAPI-PAB ]");
  8402. if (!(MapiInitLogon(OUT &lpMAPISession))) {
  8403. LUIOut(L2,"MapiInitLogon Failed");
  8404. retval = FALSE;
  8405. goto out;
  8406. }
  8407. // Get the IAddrBook - MAPI
  8408. hr = (lpMAPISession)->OpenAddressBook(
  8409. IN 0, //window handle
  8410. IN NULL, //Interface identifier
  8411. IN 0, //flags
  8412. OUT lppAdrBook); //pointer to address book object
  8413. if (HR_FAILED(hr)) {
  8414. LUIOut(L2,"OpenAddressBook Failed");
  8415. LUIOut(L3,"Could not open address book for the profile");
  8416. retval=FALSE;
  8417. goto out;
  8418. }
  8419. #endif
  8420. out:
  8421. return(retval);
  8422. }