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.

382 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. cwabobj.cpp
  5. Abstract:
  6. Interface to the windows address book.
  7. Environment:
  8. Fax send wizard
  9. Revision History:
  10. 10/23/97 -GeorgeJe-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include <windows.h>
  16. #include <prsht.h>
  17. #include <tchar.h>
  18. #include <wab.h>
  19. #include "faxui.h"
  20. #include "cwabobj.h"
  21. //
  22. // This is a global object that used for non throwing new operator.
  23. //
  24. // Using non throwing new is done by using this syntax:
  25. //
  26. // ptr = new (std::nothrow) CMyClass();
  27. //
  28. //
  29. // We had to instaciate this object since fxswzrd.dll is no longer depends on msvcp60.dll (see abobj.h for details).
  30. //
  31. //
  32. namespace std{
  33. const nothrow_t nothrow;
  34. };
  35. CWabObj::CWabObj(
  36. HINSTANCE hInstance
  37. ) : CCommonAbObj(hInstance),
  38. m_Initialized(FALSE),
  39. m_hWab(NULL),
  40. m_lpWabOpen(NULL),
  41. m_lpWABObject(NULL)
  42. /*++
  43. Routine Description:
  44. Constructor for CWabObj class
  45. Arguments:
  46. hInstance - Instance handle
  47. Return Value:
  48. NONE
  49. --*/
  50. {
  51. TCHAR szDllPath[MAX_PATH];
  52. HKEY hKey = NULL;
  53. LONG rVal;
  54. DWORD dwType;
  55. DWORD cbData = MAX_PATH * sizeof(TCHAR);
  56. HRESULT hr;
  57. m_lpAdrBook = NULL;
  58. m_lpAdrList = NULL;
  59. //
  60. // get the path to wab32.dll
  61. //
  62. rVal = RegOpenKeyEx(
  63. HKEY_LOCAL_MACHINE,
  64. REGVAL_WABPATH,
  65. 0,
  66. KEY_READ,
  67. &hKey
  68. );
  69. if (rVal == ERROR_SUCCESS)
  70. {
  71. rVal = RegQueryValueEx(
  72. hKey,
  73. TEXT(""),
  74. NULL,
  75. &dwType,
  76. (LPBYTE) szDllPath,
  77. &cbData
  78. );
  79. }
  80. if (rVal != ERROR_SUCCESS)
  81. {
  82. _tcscpy( szDllPath, TEXT("wab32.dll") );
  83. }
  84. if (hKey)
  85. {
  86. RegCloseKey( hKey );
  87. }
  88. m_hWab = LoadLibrary( szDllPath );
  89. if (m_hWab == NULL)
  90. {
  91. return;
  92. }
  93. m_lpWabOpen = (LPWABOPEN) GetProcAddress( m_hWab , "WABOpen" );
  94. if(m_lpWabOpen == NULL)
  95. {
  96. return;
  97. }
  98. //
  99. // open the wab
  100. //
  101. hr = m_lpWabOpen( &m_lpAdrBook, &m_lpWABObject, 0, 0 );
  102. if (HR_SUCCEEDED(hr))
  103. {
  104. m_Initialized = TRUE;
  105. }
  106. #ifdef UNICODE
  107. //
  108. // The WAB supports Unicode since version 5.5
  109. // So we check the version
  110. //
  111. DWORD dwRes = ERROR_SUCCESS;
  112. FAX_VERSION ver = {0};
  113. ver.dwSizeOfStruct = sizeof(ver);
  114. dwRes = GetFileVersion(szDllPath, &ver);
  115. if(ERROR_SUCCESS != dwRes)
  116. {
  117. Error(("GetFileVersion failed with %d\n", dwRes));
  118. return;
  119. }
  120. DWORD dwFileVer = (ver.wMajorVersion << 16) | ver.wMinorVersion;
  121. if(dwFileVer > 0x50000)
  122. {
  123. m_bUnicode = TRUE;
  124. }
  125. #endif // UNICODE
  126. }
  127. CWabObj::~CWabObj()
  128. /*++
  129. Routine Description:
  130. Destructor for CWabObj class
  131. Arguments:
  132. NONE
  133. Return Value:
  134. NONE
  135. --*/
  136. {
  137. if (m_lpAdrBook) {
  138. m_lpAdrBook->Release();
  139. }
  140. if (m_lpWABObject) {
  141. m_lpWABObject->Release();
  142. }
  143. if (m_hWab)
  144. {
  145. FreeLibrary( m_hWab );
  146. m_hWab = NULL;
  147. }
  148. }
  149. HRESULT
  150. CWabObj::ABAllocateBuffer(
  151. ULONG cbSize,
  152. LPVOID FAR * lppBuffer
  153. )
  154. /*++
  155. Routine Description:
  156. Arguments:
  157. Return Value:
  158. --*/
  159. {
  160. return m_lpWABObject->AllocateBuffer( cbSize, lppBuffer );
  161. }
  162. ULONG
  163. CWabObj::ABFreeBuffer(
  164. LPVOID lpBuffer
  165. )
  166. {
  167. return m_lpWABObject->FreeBuffer(lpBuffer);
  168. }
  169. extern "C"
  170. VOID
  171. FreeWabEntryID(
  172. PWIZARDUSERMEM pWizardUserMem,
  173. LPVOID lpEntryId
  174. )
  175. /*++
  176. Routine Description:
  177. C wrapper for WAB Free
  178. Arguments:
  179. pWizardUserMem - pointer to WIZARDUSERMEM structure
  180. lpEntryID - pointer to EntryId
  181. Return Value:
  182. NONE
  183. --*/
  184. {
  185. CWabObj * lpCWabObj = (CWabObj *) pWizardUserMem->lpWabInit;
  186. lpCWabObj->ABFreeBuffer(lpEntryId);
  187. }
  188. extern "C"
  189. BOOL
  190. CallWabAddress(
  191. HWND hDlg,
  192. PWIZARDUSERMEM pWizardUserMem,
  193. PRECIPIENT * ppNewRecipient
  194. )
  195. /*++
  196. Routine Description:
  197. C wrapper for CWabObj->Address
  198. Arguments:
  199. hDlg - parent window handle.
  200. pWizardUserMem - pointer to WIZARDUSERMEM structure
  201. ppNewRecipient - list to add new recipients to.
  202. Return Value:
  203. TRUE if all of the entries have a fax number.
  204. FALSE otherwise.
  205. --*/
  206. {
  207. CWabObj* lpCWabObj = (CWabObj*) pWizardUserMem->lpWabInit;
  208. return lpCWabObj->Address(
  209. hDlg,
  210. pWizardUserMem->pRecipients,
  211. ppNewRecipient
  212. );
  213. }
  214. extern "C"
  215. LPTSTR
  216. CallWabAddressEmail(
  217. HWND hDlg,
  218. PWIZARDUSERMEM pWizardUserMem
  219. )
  220. /*++
  221. Routine Description:
  222. C wrapper for CWabObj->AddressEmail
  223. Arguments:
  224. hDlg - parent window handle.
  225. pWizardUserMem - pointer to WIZARDUSERMEM structure
  226. Return Value:
  227. TRUE if found one appropriate E-mail
  228. FALSE otherwise.
  229. --*/
  230. {
  231. CWabObj* lpCWabObj = (CWabObj*) pWizardUserMem->lpWabInit;
  232. return lpCWabObj->AddressEmail(
  233. hDlg
  234. );
  235. }
  236. extern "C"
  237. LPVOID
  238. InitializeWAB(
  239. HINSTANCE hInstance
  240. )
  241. /*++
  242. Routine Description:
  243. Initialize the WAB.
  244. Arguments:
  245. hInstance - instance handle.
  246. Return Value:
  247. NONE
  248. --*/
  249. {
  250. CWabObj* lpWabObj = new (std::nothrow) CWabObj( hInstance );
  251. if ((lpWabObj!=NULL) && (!lpWabObj->isInitialized())) // constructor failed
  252. {
  253. delete lpWabObj;
  254. lpWabObj = NULL;
  255. }
  256. return (LPVOID) lpWabObj;
  257. }
  258. extern "C"
  259. VOID
  260. UnInitializeWAB(
  261. LPVOID lpVoid
  262. )
  263. /*++
  264. Routine Description:
  265. UnInitialize the WAB.
  266. Arguments:
  267. NONE
  268. Return Value:
  269. NONE
  270. --*/
  271. {
  272. CWabObj* lpWabObj = (CWabObj*) lpVoid;
  273. delete lpWabObj;
  274. }