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.

287 lines
9.0 KiB

  1. /*
  2. * MAPILAYR.C
  3. *
  4. * Layer on top of MAPI calls
  5. *
  6. * Copyright 1996 Microsoft Corporation. All Rights Reserved.
  7. *
  8. * History:
  9. * 11/14/96 BruceK First version to allow wab migration without mapi32.dll
  10. */
  11. #include "_comctl.h"
  12. #include <windows.h>
  13. #include <commctrl.h>
  14. #include <mapix.h>
  15. #include <wab.h>
  16. #include <wabguid.h>
  17. #include <wabdbg.h>
  18. #include <wabmig.h>
  19. #include "wabimp.h"
  20. #include "..\..\wab32res\resrc2.h"
  21. #include "dbgutil.h"
  22. typedef SCODE (STDMETHODCALLTYPE FREEPROWS)(
  23. LPSRowSet lpRows
  24. );
  25. typedef FREEPROWS *LPFREEPROWS;
  26. typedef SCODE (STDMETHODCALLTYPE FREEPADRLIST)(
  27. LPADRLIST lpAdrList
  28. );
  29. typedef FREEPADRLIST *LPFREEPADRLIST;
  30. typedef SCODE (STDMETHODCALLTYPE SCCOPYPROPS)(
  31. int cValues,
  32. LPSPropValue lpPropArray,
  33. LPVOID lpvDst,
  34. ULONG FAR *lpcb
  35. );
  36. typedef SCCOPYPROPS *LPSCCOPYPROPS;
  37. typedef SCODE (STDMETHODCALLTYPE SCCOUNTPROPS)(
  38. int cValues,
  39. LPSPropValue lpPropArray,
  40. ULONG FAR *lpcb
  41. );
  42. typedef SCCOUNTPROPS *LPSCCOUNTPROPS;
  43. static LPMAPIINITIALIZE lpfnMAPIInitialize = NULL;
  44. static LPMAPILOGONEX lpfnMAPILogonEx = NULL;
  45. static LPMAPIALLOCATEBUFFER lpfnMAPIAllocateBuffer = NULL;
  46. static LPMAPIALLOCATEMORE lpfnMAPIAllocateMore = NULL;
  47. static LPMAPIFREEBUFFER lpfnMAPIFreeBuffer = NULL;
  48. static LPFREEPROWS lpfnFreeProws = NULL;
  49. static LPFREEPADRLIST lpfnFreePadrlist = NULL;
  50. static LPSCCOPYPROPS lpfnScCopyProps = NULL;
  51. static LPSCCOUNTPROPS lpfnScCountProps = NULL;
  52. static HINSTANCE hinstMAPIDll = NULL;
  53. // Constant strings
  54. const TCHAR szMapiDll[] = TEXT("MAPI32.DLL");
  55. const TCHAR szMAPIAllocateBuffer[] = TEXT("MAPIAllocateBuffer");
  56. const TCHAR szMAPIAllocateMore[] = TEXT("MAPIAllocateMore");
  57. const TCHAR szMAPIFreeBuffer[] = TEXT("MAPIFreeBuffer");
  58. const TCHAR szMAPIInitialize[] = TEXT("MAPIInitialize");
  59. const TCHAR szMAPILogonEx[] = TEXT("MAPILogonEx");
  60. #if defined (_ALPHA_) || defined (ALPHA) // Bug:63053
  61. const TCHAR szFreeProws[] = TEXT("FreeProws");
  62. const TCHAR szFreePadrlist[] = TEXT("FreePadrlist");
  63. const TCHAR szScCopyProps[] = TEXT("ScCopyProps");
  64. const TCHAR szScCountProps[] = TEXT("ScCountProps");
  65. #else
  66. const TCHAR szFreeProws[] = TEXT("FreeProws@4");
  67. const TCHAR szFreePadrlist[] = TEXT("FreePadrlist@4");
  68. const TCHAR szScCopyProps[] = TEXT("ScCopyProps@16");
  69. const TCHAR szScCountProps[] = TEXT("ScCountProps@12");
  70. #endif
  71. HRESULT MAPIInitialize(LPVOID lpMapiInit) {
  72. HRESULT hResult = hrSuccess;
  73. // If MAPI DLL is not loaded, do so now.
  74. if (! hinstMAPIDll) {
  75. if (! (hinstMAPIDll = LoadLibrary(szMapiDll))) {
  76. DWORD dwErr = GetLastError();
  77. DebugTrace("Couldn't load MAPI dll [%s] -> %u\n", szMapiDll, dwErr);
  78. switch (dwErr) {
  79. case ERROR_NOT_ENOUGH_MEMORY:
  80. case ERROR_OUTOFMEMORY:
  81. hResult = ResultFromScode(MAPI_E_NOT_ENOUGH_MEMORY);
  82. break;
  83. case ERROR_HANDLE_DISK_FULL:
  84. case ERROR_DISK_FULL:
  85. hResult = ResultFromScode(MAPI_E_NOT_ENOUGH_DISK);
  86. break;
  87. default:
  88. case ERROR_FILE_NOT_FOUND:
  89. case ERROR_PATH_NOT_FOUND:
  90. hResult = ResultFromScode(MAPI_E_NOT_FOUND);
  91. break;
  92. }
  93. goto exit;
  94. } else {
  95. // Get the function pointers
  96. if (! (lpfnMAPIInitialize = (LPMAPIINITIALIZE)GetProcAddress(hinstMAPIDll,
  97. szMAPIInitialize))) {
  98. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szMAPIInitialize, szMapiDll, GetLastError());
  99. goto exit;
  100. }
  101. if (! (lpfnMAPILogonEx = (LPMAPILOGONEX)GetProcAddress(hinstMAPIDll,
  102. szMAPILogonEx))) {
  103. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szMAPILogonEx, szMapiDll, GetLastError());
  104. goto exit;
  105. }
  106. if (! (lpfnMAPIAllocateBuffer = (LPMAPIALLOCATEBUFFER)GetProcAddress(hinstMAPIDll,
  107. szMAPIAllocateBuffer))) {
  108. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szMAPIAllocateBuffer, szMapiDll, GetLastError());
  109. goto exit;
  110. }
  111. if (! (lpfnMAPIAllocateMore= (LPMAPIALLOCATEMORE)GetProcAddress(hinstMAPIDll,
  112. szMAPIAllocateMore))) {
  113. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szMAPIAllocateMore, szMapiDll, GetLastError());
  114. goto exit;
  115. }
  116. if (! (lpfnMAPIFreeBuffer = (LPMAPIFREEBUFFER)GetProcAddress(hinstMAPIDll,
  117. szMAPIFreeBuffer))) {
  118. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szMAPIFreeBuffer, szMapiDll, GetLastError());
  119. goto exit;
  120. }
  121. if (! (lpfnFreeProws= (LPFREEPROWS)GetProcAddress(hinstMAPIDll,
  122. szFreeProws))) {
  123. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szFreeProws, szMapiDll, GetLastError());
  124. goto exit;
  125. }
  126. if (! (lpfnFreePadrlist= (LPFREEPADRLIST)GetProcAddress(hinstMAPIDll,
  127. szFreePadrlist))) {
  128. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szFreePadrlist, szMapiDll, GetLastError());
  129. goto exit;
  130. }
  131. if (! (lpfnScCopyProps= (LPSCCOPYPROPS)GetProcAddress(hinstMAPIDll,
  132. szScCopyProps))) {
  133. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szScCopyProps, szMapiDll, GetLastError());
  134. goto exit;
  135. }
  136. if (! (lpfnScCountProps = (LPSCCOUNTPROPS)GetProcAddress(hinstMAPIDll,
  137. szScCountProps))) {
  138. DebugTrace("Couldn't get Fn addr %s from %s -> %u\n", szScCountProps, szMapiDll, GetLastError());
  139. goto exit;
  140. }
  141. }
  142. }
  143. exit:
  144. if (! lpfnMAPIInitialize ||
  145. ! lpfnMAPILogonEx ||
  146. ! lpfnMAPIAllocateMore ||
  147. ! lpfnMAPIAllocateBuffer ||
  148. ! lpfnMAPIFreeBuffer ||
  149. ! lpfnFreeProws ||
  150. ! lpfnFreePadrlist ||
  151. ! lpfnScCopyProps ||
  152. ! lpfnScCountProps) {
  153. // Bad news. Clean up and fail.
  154. if (hinstMAPIDll) {
  155. // unload the dll
  156. FreeLibrary(hinstMAPIDll);
  157. hinstMAPIDll = NULL;
  158. lpfnMAPIInitialize = NULL;
  159. lpfnMAPILogonEx = NULL;
  160. lpfnMAPIAllocateMore = NULL;
  161. lpfnMAPIAllocateBuffer = NULL;
  162. lpfnMAPIFreeBuffer = NULL;
  163. lpfnFreeProws = NULL;
  164. lpfnFreePadrlist = NULL;
  165. lpfnScCopyProps = NULL;
  166. lpfnScCountProps = NULL;
  167. }
  168. if (hResult == hrSuccess) {
  169. hResult = ResultFromScode(MAPI_E_NOT_FOUND);
  170. }
  171. return(hResult);
  172. }
  173. return(lpfnMAPIInitialize(lpMapiInit));
  174. }
  175. HRESULT MAPILogonEx(
  176. ULONG_PTR ulUIParam,
  177. LPTSTR lpszProfileName,
  178. LPTSTR lpszPassword,
  179. ULONG ulFlags,
  180. LPMAPISESSION FAR * lppSession
  181. ) {
  182. Assert(lpfnMAPILogonEx);
  183. if (lpfnMAPILogonEx) {
  184. return(lpfnMAPILogonEx(ulUIParam,
  185. lpszProfileName,
  186. lpszPassword,
  187. ulFlags,
  188. lppSession));
  189. } else {
  190. return(ResultFromScode(MAPI_E_NOT_INITIALIZED));
  191. }
  192. }
  193. SCODE MAPIAllocateBuffer(
  194. ULONG cbSize,
  195. LPVOID FAR * lppBuffer
  196. ) {
  197. Assert(lpfnMAPIAllocateBuffer);
  198. if (lpfnMAPIAllocateBuffer) {
  199. return(lpfnMAPIAllocateBuffer(cbSize,
  200. lppBuffer));
  201. } else {
  202. return(MAPI_E_NOT_INITIALIZED);
  203. }
  204. }
  205. SCODE MAPIAllocateMore(
  206. ULONG cbSize,
  207. LPVOID lpObject,
  208. LPVOID FAR * lppBuffer
  209. ) {
  210. Assert(lpfnMAPIAllocateMore);
  211. if (lpfnMAPIAllocateMore) {
  212. return(lpfnMAPIAllocateMore(cbSize,
  213. lpObject,
  214. lppBuffer));
  215. } else {
  216. return(MAPI_E_NOT_INITIALIZED);
  217. }
  218. }
  219. ULONG MAPIFreeBuffer(LPVOID lpBuffer) {
  220. Assert(lpfnMAPIFreeBuffer);
  221. if (lpfnMAPIFreeBuffer) {
  222. return(lpfnMAPIFreeBuffer(lpBuffer));
  223. } else {
  224. return((ULONG)MAPI_E_NOT_INITIALIZED);
  225. }
  226. }
  227. STDAPI_(SCODE)ScCountProps(int cValues, LPSPropValue lpPropArray, ULONG FAR *lpcb) {
  228. Assert(lpfnScCountProps);
  229. if (lpfnScCountProps) {
  230. return(lpfnScCountProps(cValues, lpPropArray, lpcb));
  231. } else {
  232. return((ULONG)MAPI_E_NOT_INITIALIZED);
  233. }
  234. }
  235. STDAPI_(SCODE)ScCopyProps(int cValues, LPSPropValue lpPropArray, LPVOID lpvDst,
  236. ULONG FAR *lpcb) {
  237. Assert(lpfnScCopyProps);
  238. if (lpfnScCopyProps) {
  239. return(lpfnScCopyProps(cValues, lpPropArray, lpvDst, lpcb));
  240. } else {
  241. return((ULONG)MAPI_E_NOT_INITIALIZED);
  242. }
  243. }
  244. STDAPI_(void)FreeProws(LPSRowSet lpRows) {
  245. Assert(lpfnFreeProws);
  246. if (lpfnFreeProws) {
  247. lpfnFreeProws(lpRows);
  248. }
  249. }
  250. STDAPI_(void)FreePadrlist(LPADRLIST lpadrlist) {
  251. Assert(lpfnFreePadrlist);
  252. if (lpfnFreePadrlist) {
  253. lpfnFreePadrlist(lpadrlist);
  254. }
  255. }