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.

1309 lines
41 KiB

  1. #include "wabobject.h"
  2. enum {
  3. ieidPR_DISPLAY_NAME = 0,
  4. ieidPR_ENTRYID,
  5. ieidPR_OBJECT_TYPE,
  6. ieidPR_WAB_CONF_SERVERS,
  7. ieidMax
  8. };
  9. static const SizedSPropTagArray(ieidMax, ptaEid)=
  10. {
  11. ieidMax,
  12. {
  13. PR_DISPLAY_NAME,
  14. PR_ENTRYID,
  15. PR_OBJECT_TYPE,
  16. 0x8000101e,
  17. }
  18. };
  19. enum {
  20. iemailPR_DISPLAY_NAME = 0,
  21. iemailPR_ENTRYID,
  22. iemailPR_EMAIL_ADDRESS,
  23. iemailPR_OBJECT_TYPE,
  24. iemailMax
  25. };
  26. static const SizedSPropTagArray(iemailMax, ptaEmail)=
  27. {
  28. iemailMax,
  29. {
  30. PR_DISPLAY_NAME,
  31. PR_ENTRYID,
  32. PR_EMAIL_ADDRESS,
  33. PR_OBJECT_TYPE
  34. }
  35. };
  36. enum {
  37. iphonePR_DISPLAY_NAME = 0,
  38. iphonePR_BUSINESS_TELEPHONE_NUMBER,
  39. iphonePR_HOME_TELEPHONE_NUMBER,
  40. iphonePR_ENTRYID,
  41. iphonePR_OBJECT_TYPE,
  42. iphoneMax
  43. };
  44. static const SizedSPropTagArray(iphoneMax, ptaPhone)=
  45. {
  46. iphoneMax,
  47. {
  48. PR_DISPLAY_NAME,
  49. PR_BUSINESS_TELEPHONE_NUMBER,
  50. PR_HOME_TELEPHONE_NUMBER,
  51. PR_ENTRYID,
  52. PR_OBJECT_TYPE
  53. }
  54. };
  55. enum {
  56. ibdayPR_BIRTHDAY=0,
  57. ibdayPR_DISPLAY_NAME,
  58. ibdayPR_ENTRYID,
  59. ibdayPR_OBJECT_TYPE,
  60. ibdayMax
  61. };
  62. static const SizedSPropTagArray(ibdayMax, ptaBday)=
  63. {
  64. ibdayMax,
  65. {
  66. PR_BIRTHDAY,
  67. PR_DISPLAY_NAME,
  68. PR_ENTRYID,
  69. PR_OBJECT_TYPE
  70. }
  71. };
  72. /*********************************************************************************************************/
  73. ULONG ulProps[] =
  74. {
  75. PR_DISPLAY_NAME,
  76. PR_HOME_TELEPHONE_NUMBER,
  77. PR_HOME_FAX_NUMBER,
  78. PR_CELLULAR_TELEPHONE_NUMBER,
  79. PR_BUSINESS_TELEPHONE_NUMBER,
  80. PR_BUSINESS_FAX_NUMBER,
  81. PR_PAGER_TELEPHONE_NUMBER,
  82. PR_HOME_ADDRESS_STREET,
  83. PR_HOME_ADDRESS_CITY,
  84. PR_HOME_ADDRESS_STATE_OR_PROVINCE,
  85. PR_HOME_ADDRESS_POSTAL_CODE,
  86. PR_HOME_ADDRESS_COUNTRY,
  87. PR_DEPARTMENT_NAME,
  88. PR_COMPANY_NAME,
  89. PR_OFFICE_LOCATION,
  90. PR_BUSINESS_ADDRESS_STREET,
  91. PR_BUSINESS_ADDRESS_CITY,
  92. PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE,
  93. PR_BUSINESS_ADDRESS_POSTAL_CODE,
  94. PR_BUSINESS_ADDRESS_COUNTRY,
  95. PR_PERSONAL_HOME_PAGE,
  96. PR_BUSINESS_HOME_PAGE,
  97. PR_COMMENT,
  98. };
  99. #define ulPropsMax 23
  100. enum _Parts {
  101. pMain=0,
  102. pEmail,
  103. pPhone,
  104. pHome,
  105. pBusiness,
  106. pURLS,
  107. pNotes,
  108. pEnd,
  109. pPartsMax
  110. };
  111. TCHAR szEmailPageHeader[] =
  112. "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>WAB Email Address List</title></head><body bgcolor=\"#A02303\" text=\"#FFFF00\" link=\"#FFFFFF\" vlink=\"#800000\" alink=\"#0000FF\"><div align=\"center\"><center><table border=\"0\" cellspacing=\"1\" width=\"520\" bgcolor=\"#000040\"><tr><th><font size=\"6\">Email Addresses</font></th></tr>";
  113. TCHAR szEmailPageEnd[] =
  114. "<tr><th><font size=\"6\">&nbsp;</font></th></tr></table></center></div></body></html>";
  115. LPTSTR szEmailItem[] =
  116. {
  117. "<tr><td><div align=\"center\"><center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\" width=\"250\" bgcolor=\"#F24F00\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#F24F00\">&nbsp;</td></tr><tr><td align=\"center\" width=\"250\" bgcolor=\"#F24F00\"bordercolor=\"#008080\"><font size=\"4\" face=\"Comic Sans MS\">%1</font></td><td width=\"250\" bgcolor=\"#F24F00\"><a href=\"mailto:%2\">%2</a></td></tr><tr><td align=\"center\" width=\"250\" bgcolor=\"#F24F00\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#F24F00\">&nbsp;</td></tr></table></center></div></td></tr>",
  118. "<tr><td><div align=\"center\"><center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\" width=\"250\" bgcolor=\"#3A7474\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#3A7474\">&nbsp;</td></tr><tr><td align=\"center\" width=\"250\" bgcolor=\"#3A7474\"bordercolor=\"#008080\"><font size=\"4\" face=\"Comic Sans MS\">%1</font></td><td width=\"250\" bgcolor=\"#3A7474\"><a href=\"mailto:%2\">%2</a></td></tr><tr><td align=\"center\" width=\"250\" bgcolor=\"#3A7474\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#3A7474\">&nbsp;</td></tr></table></center></div></td></tr>"
  119. };
  120. TCHAR szPhonePageHeader[] =
  121. "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>WAB Phone List</title></head><body bgcolor=\"#A02303\" text=\"#FFFF00\" link=\"#FFFFFF\" vlink=\"#800000\" alink=\"#0000FF\"><div align=\"center\"><center><table border=\"0\" cellspacing=\"1\" width=\"520\" bgcolor=\"#000040\"><tr><th><font size=\"6\">Phone List</font></th></tr><tr><td>&nbsp;</td></tr><tr><td><div align=\"center\"><center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
  122. TCHAR szPhonePageEnd[] =
  123. "</table></center></div></td></tr><tr><td>&nbsp;</td></tr></table></center></div></body></html>";
  124. LPTSTR szPhoneItem[] =
  125. {
  126. "<tr><td align=\"center\" width=\"200\" bgcolor=\"#2B69AE\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#2B69AE\">&nbsp;</td></tr><tr><td align=\"center\" valign=\"top\" width=\"200\" bgcolor=\"#2B69AE\" bordercolor=\"#008080\"><font size=\"4\" face=\"Comic Sans MS\">%1</font></td><td width=\"250\" bgcolor=\"#2B69AE\"><div align=\"left\"><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"240\" bordercolor=\"#FFFFFF\" bordercolordark=\"#2B69AE\" bordercolorlight=\"#FFFFFF\"><tr><td width=\"100\">Work:</td><td width=\"130\">%2</td></tr><tr><td width=\"100\">Home:</td><td width=\"130\">%3</td></tr></table></div></td></tr><tr><td align=\"center\" width=\"200\" bgcolor=\"#2B69AE\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#2B69AE\">&nbsp;</td></tr>",
  127. "<tr><td align=\"center\" width=\"200\" bgcolor=\"#F36565\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#F36565\">&nbsp;</td></tr><tr><td align=\"center\" valign=\"top\" width=\"200\" bgcolor=\"#F36565\" bordercolor=\"#008080\"><font size=\"4\" face=\"Comic Sans MS\">%1</font></td><td width=\"250\" bgcolor=\"#F36565\"><div align=\"left\"><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"240\" bordercolor=\"#FFFFFF\" bordercolordark=\"#F36565\" bordercolorlight=\"#FFFFFF\"><tr><td width=\"100\">Work:</td><td width=\"130\">%2</td></tr><tr><td width=\"100\">Home:</td><td width=\"130\">%3</td></tr></table></div></td></tr><tr><td align=\"center\" width=\"200\" bgcolor=\"#F36565\" bordercolor=\"#008080\">&nbsp;</td><td width=\"250\" bgcolor=\"#F36565\">&nbsp;</td></tr>",
  128. };
  129. TCHAR szDetailsPageHeader[] =
  130. "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
  131. TCHAR szDetailsPageMain[] =
  132. "<title>%1</title></head><body bgcolor=\"#A02303\" text=\"#FFFF00\" link=\"#FFFFFF\"vlink=\"#00FF00\"><div align=\"center\"><center><table border=\"1\" cellspacing=\"1\" width=\"520\" bgcolor=\"#000040\"><tr><th><font size=\"6\">%1</font></th></tr><tr><td><div align=\"center\"><center><table border=\"0\"cellspacing=\"1\"><tr>";
  133. TCHAR szEmailAddressesStart[] =
  134. "<td valign=\"top\" width=\"200\">E-mail Addresses:<div align=\"left\"><table border=\"1\" cellspacing=\"1\" bgcolor=\"#000000\" bordercolor=\"#FF0000\">";
  135. TCHAR szEmailAddressesMiddle[] =
  136. "<tr><td><font size=\"2\" face=\"Courier New\"><a href=\"mailto:%1\">%1</a></font></td></tr>";
  137. TCHAR szEmailAddressesEnd[] =
  138. "</table></div></td>";
  139. TCHAR szPhoneNumbers[] =
  140. "<td valign=\"top\" width=\"300\">Phone Numbers:<div align=\"left\"><table border=\"1\" cellspacing=\"1\"bgcolor=\"#000000\" bordercolor=\"#FF0000\"><tr><td><font size=\"2\" face=\"Courier New\">Home:</font></td><td><font size=\"2\" face=\"Courier New\">%2</font></td></tr><tr><td><font size=\"2\" face=\"Courier New\">Home Fax:</font></td><td><font size=\"2\" face=\"Courier New\">%3</font></td></tr><tr><td><font size=\"2\" face=\"Courier New\">Cellular:</font></td><td><font size=\"2\" face=\"Courier New\">%4</font></td></tr><tr><td><font size=\"2\" face=\"Courier New\">Business:</font></td><td><font size=\"2\" face=\"Courier New\">%5</font></td></tr><tr><td><font size=\"2\" face=\"Courier New\">Business-Fax:</font></td><td><font size=\"2\" face=\"Courier New\">%6</font></td></tr><tr><td><font size=\"2\" face=\"Courier New\">Pager:</font></td><td><font size=\"2\" face=\"Courier New\">%7</font></td></tr></table></div></td>";
  141. TCHAR szHomeAddress[] =
  142. "<td valign=\"top\">&nbsp;</td></tr></table></center></div></td></tr><tr><td><div align=\"center\"><center><table border=\"0\" cellspacing=\"1\"><tr><td valign=\"top\" width=\"200\">Home Address:<address>%8</address><address>%9 %10 %11</address><address>%12 </address></td>";
  143. TCHAR szBusinessAddress[] =
  144. "<td width=\"200\">Business Address:<address>%13</address><address>%14</address><address>%15</address><address>%16</address><address>%17 %18 %19</address><address>%20</address></td></tr></table></center></div></td></tr>";
  145. TCHAR szURLS[] =
  146. "<tr><td><ul><li>Personal Home Page: <a href=\"%21\">%21</a></li></ul><ul><li>Business Web Page: <a href=\"%22\">%22</a></li></ul></td></tr>";
  147. TCHAR szNotes[] =
  148. "<tr><td>Notes: %23</td></tr></table></center></div>";
  149. TCHAR szDetailsPageEnd[] =
  150. "</body></html>";
  151. TCHAR szBdayHeader[] =
  152. "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><meta name=\"GENERATOR\" content=\"Microsoft FrontPage 2.0\"><title>Birthdays</title></head><body bgcolor=\"#A02303\" text=\"#FFFF00\" link=\"#FFFFFF\" vlink=\"#800000\" alink=\"#0000FF\"><div align=\"center\"><center><table border=\"0\" cellspacing=\"1\" width=\"520\" bgcolor=\"#000040\"><tr><th><font color=\"#C0C0C0\" size=\"6\">Birthdays</font></th></tr><tr><td><table border=\"0\" cellspacing=\"1\" width=\"100%\">";
  153. TCHAR szBdayEnd[] =
  154. "</table></td></tr><tr><td>&nbsp;</td></tr></table></center></div></body></html>";
  155. TCHAR szBdaySingleItem[] =
  156. "<tr><td width=\"100\">&nbsp;</td><td align=\"right\" width=\"200\"><ul><li><p align=\"left\"><font size=\"4\" face=\"Comic Sans MS\">%2</font></p></li></ul></td><td align=\"right\" width=\"100\"><p align=\"center\"><font size=\"4\" face=\"Comic Sans MS\"><em>%1</em></font></p></td></tr>";
  157. LPTSTR szBdayMonthItemStart[] =
  158. {
  159. "<tr><td width=\"250\" bgcolor=\"#2B69AE\"><blockquote><h1><font color=\"#80FFFF\" size=\"5\" face=\"Comic Sans MS\">%1</font></h1></blockquote><div align=\"center\"><center><table border=\"0\" cellspacing=\"1\" width=\"400\">",
  160. "<tr><td width=\"250\" bgcolor=\"#77943A\"><blockquote><h1><font color=\"#80FFFF\" size=\"5\" face=\"Comic Sans MS\">%1</font></h1></blockquote><div align=\"center\"><center><table border=\"0\" cellspacing=\"1\" width=\"400\">",
  161. };
  162. TCHAR szBdayMonthItemEnd[]=
  163. "</table></center></div></td></tr><tr><td>&nbsp;</td></tr>";
  164. const LPTSTR szMonth[] =
  165. {
  166. "January", "February", "March", "April", "May", "June",
  167. "July", "August", "September", "October", "November", "December"
  168. };
  169. /*********************************************************************************************************/
  170. // contructor
  171. CWAB::CWAB()
  172. {
  173. // Here we load the WAB Object and initialize it
  174. m_bInitialized = FALSE;
  175. {
  176. TCHAR szWABDllPath[MAX_PATH];
  177. DWORD dwType = 0;
  178. ULONG cbData = sizeof(szWABDllPath);
  179. HKEY hKey = NULL;
  180. *szWABDllPath = '\0';
  181. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
  182. RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
  183. if(hKey) RegCloseKey(hKey);
  184. m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
  185. }
  186. if(m_hinstWAB)
  187. m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
  188. if(m_lpfnWABOpen)
  189. {
  190. HRESULT hr = E_FAIL;
  191. hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,NULL,0);
  192. if(!hr)
  193. m_bInitialized = TRUE;
  194. }
  195. }
  196. CWAB::~CWAB()
  197. {
  198. if(m_bInitialized)
  199. {
  200. if(m_lpAdrBook)
  201. m_lpAdrBook->Release();
  202. if(m_lpWABObject)
  203. m_lpWABObject->Release();
  204. if(m_hinstWAB)
  205. FreeLibrary(m_hinstWAB);
  206. }
  207. }
  208. void CWAB::ClearWABLVContents(CListCtrl * pListView)
  209. {
  210. int i;
  211. int nCount = pListView->GetItemCount();
  212. if(nCount<=0)
  213. return;
  214. for(i=0;i<nCount;i++)
  215. {
  216. LV_ITEM lvi ={0};
  217. lvi.mask = LVIF_PARAM;
  218. lvi.iItem = i;
  219. lvi.iSubItem = 0;
  220. pListView->GetItem(&lvi);
  221. if(lvi.lParam)
  222. {
  223. LPSBinary lpSB = (LPSBinary) lvi.lParam;
  224. m_lpWABObject->FreeBuffer(lpSB);
  225. }
  226. }
  227. pListView->DeleteAllItems();
  228. }
  229. HRESULT CWAB::LoadWABContents(CListCtrl * pListView)
  230. {
  231. ULONG ulObjType = 0;
  232. LPMAPITABLE lpAB = NULL;
  233. LPTSTR * lppszArray=NULL;
  234. ULONG cRows = 0;
  235. LPSRowSet lpRow = NULL;
  236. LPSRowSet lpRowAB = NULL;
  237. LPABCONT lpContainer = NULL;
  238. HRESULT hr = E_FAIL;
  239. ULONG lpcbEID;
  240. LPENTRYID lpEID = NULL;
  241. hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
  242. ulObjType = 0;
  243. hr = m_lpAdrBook->OpenEntry(lpcbEID,
  244. (LPENTRYID)lpEID,
  245. NULL,
  246. 0,
  247. &ulObjType,
  248. (LPUNKNOWN *)&lpContainer);
  249. m_lpWABObject->FreeBuffer(lpEID);
  250. lpEID = NULL;
  251. hr = lpContainer->GetContentsTable( 0,
  252. &lpAB);
  253. if ( SUCCEEDED(hr) )
  254. hr =lpAB->SetColumns( (LPSPropTagArray)&ptaEid, 0 );
  255. if ( SUCCEEDED(hr) )
  256. hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
  257. int cNumRows = 0;
  258. int nRows=0;
  259. do {
  260. if ( SUCCEEDED(hr) )
  261. hr = lpAB->QueryRows(1, 0, &lpRowAB);
  262. if(lpRowAB)
  263. {
  264. cNumRows = lpRowAB->cRows;
  265. if ( SUCCEEDED(hr) && cNumRows)
  266. {
  267. LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
  268. LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
  269. ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
  270. if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER)
  271. {
  272. LPSBinary lpSB = NULL;
  273. m_lpWABObject->AllocateBuffer(sizeof(SBinary), (LPVOID *) &lpSB);
  274. if(lpSB)
  275. {
  276. m_lpWABObject->AllocateMore(cbEID, lpSB, (LPVOID *) &(lpSB->lpb));
  277. if(!lpSB->lpb)
  278. {
  279. m_lpWABObject->FreeBuffer(lpSB);
  280. continue;
  281. }
  282. CopyMemory(lpSB->lpb, lpEID, cbEID);
  283. lpSB->cb = cbEID;
  284. LV_ITEM lvi = {0};
  285. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  286. lvi.iItem = pListView->GetItemCount();
  287. lvi.iSubItem = 0;
  288. lvi.pszText = lpsz;
  289. lvi.lParam = (LPARAM) lpSB;
  290. // Now add this item to the list view
  291. pListView->InsertItem(&lvi);
  292. }
  293. }
  294. }
  295. FreeProws(lpRowAB );
  296. }
  297. }while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ;
  298. if ( lpContainer )
  299. lpContainer->Release();
  300. if ( lpAB )
  301. lpAB->Release();
  302. return hr;
  303. }
  304. BOOL CWAB::CreatePhoneListFileFromWAB(LPTSTR szFileName)
  305. {
  306. BOOL bRet = FALSE;
  307. ULONG ulObjType = 0;
  308. LPMAPITABLE lpAB = NULL;
  309. LPTSTR * lppszArray=NULL;
  310. ULONG cRows = 0;
  311. LPSRowSet lpRow = NULL;
  312. LPSRowSet lpRowAB = NULL;
  313. LPABCONT lpContainer = NULL;
  314. HRESULT hr = E_FAIL;
  315. ULONG lpcbEID;
  316. LPENTRYID lpEID = NULL;
  317. TCHAR szDir[MAX_PATH];
  318. GetTempPath(MAX_PATH, szDir);
  319. lstrcpy(szFileName, szDir);
  320. lstrcat(szFileName, "temp.htm");
  321. hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
  322. ulObjType = 0;
  323. hr = m_lpAdrBook->OpenEntry(lpcbEID,
  324. (LPENTRYID)lpEID,
  325. NULL,
  326. 0,
  327. &ulObjType,
  328. (LPUNKNOWN *)&lpContainer);
  329. m_lpWABObject->FreeBuffer(lpEID);
  330. lpEID = NULL;
  331. hr = lpContainer->GetContentsTable( 0,
  332. &lpAB);
  333. if ( SUCCEEDED(hr) )
  334. hr =lpAB->SetColumns( (LPSPropTagArray)&ptaPhone, 0 );
  335. if ( SUCCEEDED(hr) )
  336. hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
  337. int cNumRows = 0;
  338. int nRows=0;
  339. HANDLE hFile = NULL;
  340. DWORD dw;
  341. hFile = CreateFile( szFileName,
  342. GENERIC_WRITE,
  343. 0, // sharing
  344. NULL,
  345. CREATE_ALWAYS,
  346. FILE_FLAG_SEQUENTIAL_SCAN,
  347. NULL);
  348. if(hFile != INVALID_HANDLE_VALUE)
  349. {
  350. WriteFile( hFile,
  351. (LPCVOID) szPhonePageHeader,
  352. (DWORD) lstrlen(szPhonePageHeader),
  353. &dw,
  354. NULL);
  355. }
  356. int nType = 0;
  357. do {
  358. if ( SUCCEEDED(hr) )
  359. hr = lpAB->QueryRows(1, 0, &lpRowAB);
  360. if(lpRowAB)
  361. {
  362. cNumRows = lpRowAB->cRows;
  363. LPTSTR sz[iphoneMax];
  364. if ( SUCCEEDED(hr) && cNumRows)
  365. {
  366. int i;
  367. for(i=0;i<iphoneMax-2;i++)
  368. {
  369. sz[i] = lpRowAB->aRow[0].lpProps[i].Value.lpszA;
  370. if(!sz[i] || !lstrlen(sz[i]))
  371. sz[i] = TEXT("&nbsp;");
  372. }
  373. if(lpRowAB->aRow[0].lpProps[iphonePR_OBJECT_TYPE].Value.l == MAPI_MAILUSER)
  374. {
  375. LPTSTR lpPhoneItem =NULL;
  376. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  377. szPhoneItem[nType],
  378. 0, 0, //ignored
  379. (LPTSTR) &lpPhoneItem, 0,
  380. (va_list *)sz);
  381. nType = 1- nType;
  382. if(lpPhoneItem)
  383. {
  384. if(hFile != INVALID_HANDLE_VALUE)
  385. {
  386. WriteFile( hFile,
  387. (LPCVOID) lpPhoneItem,
  388. (DWORD) lstrlen(lpPhoneItem),
  389. &dw,
  390. NULL);
  391. }
  392. LocalFree(lpPhoneItem);
  393. }
  394. }
  395. }
  396. FreeProws(lpRowAB );
  397. }
  398. }while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ;
  399. if(hFile != INVALID_HANDLE_VALUE)
  400. {
  401. WriteFile( hFile,
  402. (LPCVOID) szPhonePageEnd,
  403. (DWORD) lstrlen(szPhonePageEnd),
  404. &dw,
  405. NULL);
  406. CloseHandle(hFile);
  407. }
  408. if ( lpContainer )
  409. lpContainer->Release();
  410. if ( lpAB )
  411. lpAB->Release();
  412. return bRet;
  413. }
  414. BOOL CWAB::CreateEmailListFileFromWAB(LPTSTR szFileName)
  415. {
  416. BOOL bRet = FALSE;
  417. ULONG ulObjType = 0;
  418. LPMAPITABLE lpAB = NULL;
  419. LPTSTR * lppszArray=NULL;
  420. ULONG cRows = 0;
  421. LPSRowSet lpRow = NULL;
  422. LPSRowSet lpRowAB = NULL;
  423. LPABCONT lpContainer = NULL;
  424. HRESULT hr = E_FAIL;
  425. ULONG lpcbEID;
  426. LPENTRYID lpEID = NULL;
  427. TCHAR szDir[MAX_PATH];
  428. GetTempPath(MAX_PATH, szDir);
  429. lstrcpy(szFileName, szDir);
  430. lstrcat(szFileName, "temp.htm");
  431. hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
  432. ulObjType = 0;
  433. hr = m_lpAdrBook->OpenEntry(lpcbEID,
  434. (LPENTRYID)lpEID,
  435. NULL,
  436. 0,
  437. &ulObjType,
  438. (LPUNKNOWN *)&lpContainer);
  439. m_lpWABObject->FreeBuffer(lpEID);
  440. lpEID = NULL;
  441. hr = lpContainer->GetContentsTable( 0,
  442. &lpAB);
  443. if ( SUCCEEDED(hr) )
  444. hr =lpAB->SetColumns( (LPSPropTagArray)&ptaEmail, 0 );
  445. if ( SUCCEEDED(hr) )
  446. hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
  447. int cNumRows = 0;
  448. int nRows=0;
  449. HANDLE hFile = NULL;
  450. DWORD dw;
  451. hFile = CreateFile( szFileName,
  452. GENERIC_WRITE,
  453. 0, // sharing
  454. NULL,
  455. CREATE_ALWAYS,
  456. FILE_FLAG_SEQUENTIAL_SCAN,
  457. NULL);
  458. if(hFile != INVALID_HANDLE_VALUE)
  459. {
  460. WriteFile( hFile,
  461. (LPCVOID) szEmailPageHeader,
  462. (DWORD) lstrlen(szEmailPageHeader),
  463. &dw,
  464. NULL);
  465. }
  466. int nType = 0;
  467. do {
  468. if ( SUCCEEDED(hr) )
  469. hr = lpAB->QueryRows(1, 0, &lpRowAB);
  470. if(lpRowAB)
  471. {
  472. cNumRows = lpRowAB->cRows;
  473. LPTSTR sz[2];
  474. if ( SUCCEEDED(hr) && cNumRows)
  475. {
  476. sz[0] = lpRowAB->aRow[0].lpProps[iemailPR_DISPLAY_NAME].Value.lpszA;
  477. sz[1] = lpRowAB->aRow[0].lpProps[iemailPR_EMAIL_ADDRESS].Value.lpszA;
  478. if(!sz[1] || !lstrlen(sz[1]))
  479. sz[1] = "No E-mail";
  480. if(lpRowAB->aRow[0].lpProps[iemailPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER)
  481. {
  482. LPTSTR lpEmailItem =NULL;
  483. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  484. szEmailItem[nType],
  485. 0, 0, //ignored
  486. (LPTSTR) &lpEmailItem, 0,
  487. (va_list *)sz);
  488. nType = 1- nType;
  489. if(lpEmailItem)
  490. {
  491. if(hFile != INVALID_HANDLE_VALUE)
  492. {
  493. WriteFile( hFile,
  494. (LPCVOID) lpEmailItem,
  495. (DWORD) lstrlen(lpEmailItem),
  496. &dw,
  497. NULL);
  498. }
  499. LocalFree(lpEmailItem);
  500. }
  501. }
  502. }
  503. FreeProws(lpRowAB );
  504. }
  505. }while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ;
  506. if(hFile != INVALID_HANDLE_VALUE)
  507. {
  508. WriteFile( hFile,
  509. (LPCVOID) szEmailPageEnd,
  510. (DWORD) lstrlen(szEmailPageEnd),
  511. &dw,
  512. NULL);
  513. CloseHandle(hFile);
  514. }
  515. if ( lpContainer )
  516. lpContainer->Release();
  517. if ( lpAB )
  518. lpAB->Release();
  519. return bRet;
  520. }
  521. BOOL CWAB::CreateBirthdayFileFromWAB(LPTSTR szFileName)
  522. {
  523. BOOL bRet = FALSE;
  524. ULONG ulObjType = 0;
  525. LPMAPITABLE lpAB = NULL;
  526. LPTSTR * lppszArray=NULL;
  527. ULONG cRows = 0;
  528. LPSRowSet lpRow = NULL;
  529. LPSRowSet lpRowAB = NULL;
  530. LPABCONT lpContainer = NULL;
  531. HRESULT hr = E_FAIL;
  532. ULONG lpcbEID;
  533. LPENTRYID lpEID = NULL;
  534. TCHAR szDir[MAX_PATH];
  535. GetTempPath(MAX_PATH, szDir);
  536. lstrcpy(szFileName, szDir);
  537. lstrcat(szFileName, "temp.htm");
  538. hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
  539. ulObjType = 0;
  540. hr = m_lpAdrBook->OpenEntry(lpcbEID,
  541. (LPENTRYID)lpEID,
  542. NULL,
  543. 0,
  544. &ulObjType,
  545. (LPUNKNOWN *)&lpContainer);
  546. m_lpWABObject->FreeBuffer(lpEID);
  547. lpEID = NULL;
  548. hr = lpContainer->GetContentsTable( 0,
  549. &lpAB);
  550. if ( SUCCEEDED(hr) )
  551. hr =lpAB->SetColumns( (LPSPropTagArray)&ptaBday, 0 );
  552. int cNumRows = 0;
  553. int nRows=0;
  554. HANDLE hFile = NULL;
  555. DWORD dw;
  556. hFile = CreateFile( szFileName,
  557. GENERIC_WRITE,
  558. 0, // sharing
  559. NULL,
  560. CREATE_ALWAYS,
  561. FILE_FLAG_SEQUENTIAL_SCAN,
  562. NULL);
  563. if(hFile != INVALID_HANDLE_VALUE)
  564. {
  565. WriteFile( hFile,
  566. (LPCVOID) szBdayHeader,
  567. (DWORD) lstrlen(szBdayHeader),
  568. &dw,
  569. NULL);
  570. }
  571. int nType = 0;
  572. int LastMonth = 0;
  573. BOOL bMonthSet = FALSE;
  574. for(LastMonth=1;LastMonth<=12;LastMonth++)
  575. {
  576. bMonthSet = FALSE;
  577. if ( SUCCEEDED(hr) )
  578. hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
  579. do {
  580. if ( SUCCEEDED(hr) )
  581. hr = lpAB->QueryRows(1, 0, &lpRowAB);
  582. if(lpRowAB)
  583. {
  584. cNumRows = lpRowAB->cRows;
  585. if ( SUCCEEDED(hr) && cNumRows)
  586. {
  587. if( lpRowAB->aRow[0].lpProps[ibdayPR_BIRTHDAY].ulPropTag == PR_BIRTHDAY &&
  588. lpRowAB->aRow[0].lpProps[ibdayPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER)
  589. {
  590. FILETIME ft = lpRowAB->aRow[0].lpProps[ibdayPR_BIRTHDAY].Value.ft;
  591. SYSTEMTIME st;
  592. FileTimeToSystemTime(&ft, &st);
  593. if(st.wMonth == LastMonth)
  594. {
  595. if(bMonthSet == FALSE)
  596. {
  597. nType = 1- nType;
  598. LPTSTR lpMonthItem =NULL;
  599. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  600. szBdayMonthItemStart[nType],
  601. 0, 0, //ignored
  602. (LPTSTR) &lpMonthItem, 0,
  603. (va_list *)&szMonth[LastMonth-1]);
  604. if(lpMonthItem)
  605. {
  606. if(hFile != INVALID_HANDLE_VALUE)
  607. {
  608. WriteFile( hFile,
  609. (LPCVOID) lpMonthItem,
  610. (DWORD) lstrlen(lpMonthItem),
  611. &dw,
  612. NULL);
  613. }
  614. LocalFree(lpMonthItem);
  615. }
  616. bMonthSet = TRUE;
  617. }
  618. LPTSTR lpBdayItem = NULL;
  619. LPTSTR sz[2];
  620. TCHAR szDate[256];
  621. wsprintf(szDate,"%d",st.wDay);
  622. sz[0] = szDate;
  623. sz[1] = lpRowAB->aRow[0].lpProps[ibdayPR_DISPLAY_NAME].Value.LPSZ;
  624. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  625. szBdaySingleItem,
  626. 0, 0, //ignored
  627. (LPTSTR) &lpBdayItem, 0,
  628. (va_list *)sz);
  629. if(lpBdayItem)
  630. {
  631. if(hFile != INVALID_HANDLE_VALUE)
  632. {
  633. WriteFile( hFile,
  634. (LPCVOID) lpBdayItem,
  635. (DWORD) lstrlen(lpBdayItem),
  636. &dw,
  637. NULL);
  638. }
  639. LocalFree(lpBdayItem);
  640. }
  641. }
  642. }
  643. }
  644. FreeProws(lpRowAB );
  645. }
  646. }while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ;
  647. if(bMonthSet)
  648. {
  649. if(hFile != INVALID_HANDLE_VALUE)
  650. {
  651. WriteFile( hFile,
  652. (LPCVOID) szBdayMonthItemEnd,
  653. (DWORD) lstrlen(szBdayMonthItemEnd),
  654. &dw,
  655. NULL);
  656. }
  657. }
  658. }//for
  659. if(hFile != INVALID_HANDLE_VALUE)
  660. {
  661. if(LastMonth > 0)
  662. {
  663. WriteFile( hFile,
  664. (LPCVOID) szBdayMonthItemEnd,
  665. (DWORD) lstrlen(szBdayMonthItemEnd),
  666. &dw,
  667. NULL);
  668. }
  669. WriteFile( hFile,
  670. (LPCVOID) szBdayEnd,
  671. (DWORD) lstrlen(szBdayEnd),
  672. &dw,
  673. NULL);
  674. CloseHandle(hFile);
  675. }
  676. if ( lpContainer )
  677. lpContainer->Release();
  678. if ( lpAB )
  679. lpAB->Release();
  680. return bRet;
  681. }
  682. BOOL CWAB::CreateDetailsFileFromWAB(CListCtrl * pListView, LPTSTR szFileName)
  683. {
  684. BOOL bRet = FALSE;
  685. TCHAR szDir[MAX_PATH];
  686. LV_ITEM lvi = {0};
  687. LPMAILUSER lpMailUser = NULL;
  688. ULONG ulcProps;
  689. LPSPropValue lpPropArray = NULL;
  690. if(!szFileName)
  691. goto out;
  692. *szFileName = '\0';
  693. if(!m_bDetailsOn) // This is not a details view
  694. goto out;
  695. // Get the Selected Item from the listview
  696. lvi.mask = LVIF_PARAM;
  697. lvi.iItem = pListView->GetNextItem(-1, LVNI_SELECTED);
  698. if(lvi.iItem == -1)
  699. goto out;
  700. lvi.iSubItem = 0;
  701. GetTempPath(MAX_PATH, szDir);
  702. lstrcpy(szFileName, szDir);
  703. lstrcat(szFileName, "temp.htm");
  704. pListView->GetItem(&lvi);
  705. if(lvi.lParam)
  706. {
  707. LPSBinary lpSB = (LPSBinary) lvi.lParam;
  708. ULONG ulObjType;
  709. HRESULT hr = E_FAIL;
  710. hr = m_lpAdrBook->OpenEntry(lpSB->cb,
  711. (LPENTRYID) lpSB->lpb,
  712. NULL, // interface
  713. 0, // flags
  714. &ulObjType,
  715. (LPUNKNOWN *)&lpMailUser);
  716. if(hr || !lpMailUser)
  717. goto out;
  718. lpMailUser->GetProps(NULL, 0, &ulcProps, &lpPropArray);
  719. if(lpPropArray)
  720. {
  721. LPTSTR lpsz[ulPropsMax];
  722. LPTSTR szEmpty = "";
  723. ULONG i,j,nEmail = -1;
  724. for(i=0;i<ulPropsMax;i++)
  725. {
  726. lpsz[i] = szEmpty;
  727. for(j=0;j<ulcProps;j++)
  728. {
  729. if(lpPropArray[j].ulPropTag == ulProps[i])
  730. {
  731. lpsz[i] = lpPropArray[j].Value.LPSZ;
  732. break;
  733. }
  734. }
  735. }
  736. LPTSTR lp[pPartsMax];
  737. LPTSTR lpTemplate[pPartsMax];
  738. LPTSTR lpFile;
  739. lpTemplate[pMain] = (LPTSTR) szDetailsPageMain;
  740. lpTemplate[pPhone] = (LPTSTR) szPhoneNumbers;
  741. lpTemplate[pHome] = (LPTSTR) szHomeAddress;
  742. lpTemplate[pBusiness] = (LPTSTR) szBusinessAddress;
  743. lpTemplate[pURLS] = (LPTSTR) szURLS;
  744. lpTemplate[pNotes] = (LPTSTR) szNotes;
  745. lpTemplate[pEnd] = (LPTSTR) szDetailsPageEnd;
  746. lpTemplate[pEmail] = NULL;
  747. for(i=0;i<pPartsMax;i++)
  748. lp[i]=NULL;
  749. for(i=0;i<pPartsMax;i++)
  750. {
  751. if(i!=pEmail)
  752. {
  753. // use format message to create the various message components
  754. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  755. lpTemplate[i],
  756. 0, 0, //ignored
  757. (LPTSTR) &(lp[i]), 0,
  758. (va_list *)lpsz);
  759. }
  760. }
  761. for(j=0;j<ulcProps;j++)
  762. {
  763. if(lpPropArray[j].ulPropTag == PR_CONTACT_EMAIL_ADDRESSES)
  764. {
  765. nEmail = j;
  766. break;
  767. }
  768. }
  769. // Get the email addresses
  770. if(nEmail != -1)
  771. {
  772. int nCount = lpPropArray[nEmail].Value.MVSZ.cValues;
  773. LPTSTR lpEmail[10];
  774. if(nCount>10)
  775. nCount = 10;
  776. {
  777. int i, nLen = 0;
  778. for(i=0;i<nCount;i++)
  779. {
  780. lpEmail[i] = szEmpty;
  781. if(lstrlen(lpPropArray[nEmail].Value.MVSZ.LPPSZ[i]))
  782. {
  783. // use format message to create the various message components
  784. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  785. szEmailAddressesMiddle,
  786. 0, 0, //ignored
  787. (LPTSTR) &(lpEmail[i]), 0,
  788. (va_list *)&(lpPropArray[nEmail].Value.MVSZ.LPPSZ[i]));
  789. nLen += lstrlen(lpEmail[i]);
  790. }
  791. }
  792. nLen+= lstrlen(szEmailAddressesStart);
  793. nLen+= lstrlen(szEmailAddressesEnd);
  794. nLen++;
  795. lp[pEmail] = (LPTSTR) LocalAlloc(LMEM_ZEROINIT, nLen);
  796. if(lp[pEmail])
  797. {
  798. lstrcpy(lp[pEmail], szEmpty);
  799. lstrcat(lp[pEmail], szEmailAddressesStart);
  800. for(i=0;i<nCount;i++)
  801. lstrcat(lp[pEmail], lpEmail[i]);
  802. lstrcat(lp[pEmail], szEmailAddressesEnd);
  803. }
  804. for(i=0;i<nCount;i++)
  805. LocalFree(lpEmail[i]);
  806. }
  807. }
  808. else
  809. {
  810. // Didnt find CONTACT_EMAIL_ADDRESSES .. just look for email address
  811. for(j=0;j<ulcProps;j++)
  812. {
  813. if(lpPropArray[j].ulPropTag == PR_EMAIL_ADDRESS)
  814. {
  815. nEmail = j;
  816. break;
  817. }
  818. }
  819. if(nEmail!= -1)
  820. {
  821. LPTSTR lpEmail = NULL;
  822. int nLen = 0;
  823. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  824. szEmailAddressesMiddle,
  825. 0, 0, //ignored
  826. (LPTSTR) &(lpEmail), 0,
  827. (va_list *)&(lpPropArray[nEmail].Value.LPSZ));
  828. nLen += lstrlen(lpEmail);
  829. nLen+= lstrlen(szEmailAddressesStart);
  830. nLen+= lstrlen(szEmailAddressesEnd);
  831. nLen++;
  832. lp[pEmail] = (LPTSTR) LocalAlloc(LMEM_ZEROINIT, nLen);
  833. if(lp[pEmail])
  834. {
  835. lstrcpy(lp[pEmail], szEmpty);
  836. lstrcat(lp[pEmail], szEmailAddressesStart);
  837. lstrcat(lp[pEmail], lpEmail);
  838. lstrcat(lp[pEmail], szEmailAddressesEnd);
  839. }
  840. if(lpEmail)
  841. LocalFree(lpEmail);
  842. }
  843. }
  844. int nLen = 0;
  845. for(i=0;i<pPartsMax;i++)
  846. {
  847. if(lp[i])
  848. nLen += lstrlen(lp[i]);
  849. }
  850. nLen++;
  851. lpFile = (LPTSTR) LocalAlloc(LMEM_ZEROINIT, nLen);
  852. if(lpFile)
  853. {
  854. lstrcpy(lpFile, szEmpty);
  855. for(i=0;i<pPartsMax;i++)
  856. {
  857. if(lp[i])
  858. lstrcat(lpFile,lp[i]);
  859. }
  860. HANDLE hFile = NULL;
  861. if (INVALID_HANDLE_VALUE != (hFile = CreateFile( szFileName,
  862. GENERIC_WRITE,
  863. 0, // sharing
  864. NULL,
  865. CREATE_ALWAYS,
  866. FILE_FLAG_SEQUENTIAL_SCAN,
  867. NULL)))
  868. {
  869. DWORD dw;
  870. WriteFile( hFile,
  871. (LPCVOID) lpFile,
  872. (DWORD) lstrlen(lpFile)+1,
  873. &dw,
  874. NULL);
  875. CloseHandle(hFile);
  876. }
  877. LocalFree(lpFile);
  878. }
  879. for(i=0;i<pPartsMax;i++)
  880. {
  881. if(lp[i])
  882. LocalFree(lp[i]);
  883. }
  884. }
  885. }
  886. bRet = TRUE;
  887. out:
  888. if(lpPropArray)
  889. m_lpWABObject->FreeBuffer(lpPropArray);
  890. if(lpMailUser)
  891. lpMailUser->Release();
  892. return bRet;
  893. }
  894. void CWAB::FreeProws(LPSRowSet prows)
  895. {
  896. ULONG irow;
  897. if (!prows)
  898. return;
  899. for (irow = 0; irow < prows->cRows; ++irow)
  900. m_lpWABObject->FreeBuffer(prows->aRow[irow].lpProps);
  901. m_lpWABObject->FreeBuffer(prows);
  902. }
  903. void CWAB::SetDetailsOn(BOOL bOn)
  904. {
  905. m_bDetailsOn = bOn;
  906. }
  907. void CWAB::ShowSelectedItemDetails(HWND hWndParent, CListCtrl * pListView)
  908. {
  909. HRESULT hr = S_OK;
  910. LV_ITEM lvi = {0};
  911. // Get the Selected Item from the listview
  912. lvi.mask = LVIF_PARAM;
  913. lvi.iSubItem = 0;
  914. lvi.iItem = pListView->GetNextItem(-1, LVNI_SELECTED);
  915. if(lvi.iItem == -1)
  916. return;
  917. pListView->GetItem(&lvi);
  918. if(lvi.lParam)
  919. {
  920. HWND hWnd = NULL;
  921. LPSBinary lpSB = (LPSBinary) lvi.lParam;
  922. hr = m_lpAdrBook->Details( (LPULONG) &hWnd, // ulUIParam
  923. NULL,
  924. NULL,
  925. lpSB->cb,
  926. (LPENTRYID) lpSB->lpb,
  927. NULL,
  928. NULL,
  929. NULL,
  930. 0);
  931. if(hr)
  932. {
  933. TCHAR sz[MAX_PATH];
  934. wsprintf(sz, "Error: %x GetLastError: %d\n",hr, GetLastError());
  935. OutputDebugString(sz);
  936. }
  937. }
  938. return;
  939. }
  940. BOOL CWAB::GetSelectedItemBirthday(CListCtrl * pListView, SYSTEMTIME * lpst)
  941. {
  942. BOOL bRet = FALSE;
  943. LV_ITEM lvi = {0};
  944. // Get the Selected Item from the listview
  945. lvi.mask = LVIF_PARAM;
  946. lvi.iSubItem = 0;
  947. lvi.iItem = pListView->GetNextItem(-1, LVNI_SELECTED);
  948. if(lvi.iItem == -1)
  949. goto out;
  950. pListView->GetItem(&lvi);
  951. if(lvi.lParam)
  952. {
  953. LPMAILUSER lpMailUser = NULL;
  954. LPSBinary lpSB = (LPSBinary) lvi.lParam;
  955. ULONG ulObjType = 0;
  956. m_lpAdrBook->OpenEntry(lpSB->cb,
  957. (LPENTRYID) lpSB->lpb,
  958. NULL, // interface
  959. 0, // flags
  960. &ulObjType,
  961. (LPUNKNOWN *)&lpMailUser);
  962. if(lpMailUser)
  963. {
  964. ULONG cProps;
  965. LPSPropValue lpPropArray = NULL;
  966. SizedSPropTagArray(1, ptaBday) =
  967. {
  968. 1,
  969. { PR_BIRTHDAY }
  970. };
  971. lpMailUser->GetProps((LPSPropTagArray) &ptaBday, 0, &cProps, &lpPropArray);
  972. if(lpPropArray)
  973. {
  974. if(lpPropArray[0].ulPropTag == PR_BIRTHDAY)
  975. {
  976. FILETIME ft = lpPropArray[0].Value.ft;
  977. if(FileTimeToSystemTime(&ft, lpst))
  978. {
  979. bRet = TRUE;
  980. }
  981. }
  982. m_lpWABObject->FreeBuffer(lpPropArray);
  983. }
  984. lpMailUser->Release();
  985. }
  986. }
  987. out:
  988. return bRet;
  989. }
  990. void CWAB::SetSelectedItemBirthday(CListCtrl * pListView, SYSTEMTIME st)
  991. {
  992. LV_ITEM lvi = {0};
  993. // Get the Selected Item from the listview
  994. lvi.mask = LVIF_PARAM;
  995. lvi.iSubItem = 0;
  996. lvi.iItem = pListView->GetNextItem(-1, LVNI_SELECTED);
  997. if(lvi.iItem == -1)
  998. goto out;
  999. pListView->GetItem(&lvi);
  1000. if(lvi.lParam)
  1001. {
  1002. LPMAILUSER lpMailUser = NULL;
  1003. LPSBinary lpSB = (LPSBinary) lvi.lParam;
  1004. ULONG ulObjType = 0;
  1005. m_lpAdrBook->OpenEntry(lpSB->cb,
  1006. (LPENTRYID) lpSB->lpb,
  1007. NULL, // interface
  1008. MAPI_MODIFY, // flags
  1009. &ulObjType,
  1010. (LPUNKNOWN *)&lpMailUser);
  1011. if(lpMailUser)
  1012. {
  1013. ULONG cProps;
  1014. SPropValue PropArray = {0};
  1015. cProps = 1;
  1016. PropArray.ulPropTag = PR_BIRTHDAY;
  1017. FILETIME ft;
  1018. if(SystemTimeToFileTime(&st, &ft))
  1019. {
  1020. PropArray.Value.ft = ft;
  1021. if(S_OK == lpMailUser->SetProps(cProps, &PropArray, NULL))
  1022. {
  1023. lpMailUser->SaveChanges(KEEP_OPEN_READWRITE);
  1024. }
  1025. }
  1026. lpMailUser->Release();
  1027. }
  1028. }
  1029. out:
  1030. return;
  1031. }