WabCode.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. {******************************************************************}
  2. { }
  3. { Borland Delphi Runtime Library }
  4. { Windows Address Book (WAB) functions interface unit }
  5. { }
  6. { Portions created by Microsoft are }
  7. { Copyright (C) 1995-2000 Microsoft Corporation. }
  8. { All Rights Reserved. }
  9. { }
  10. { The original file is: wabcode.h, released 31 Jan 2000. }
  11. { The original Pascal code is: WabCode.pas, released 15 Mar 2000. }
  12. { The initial developer of the Pascal code is Petr Vones }
  13. { (petr.v@mujmail.cz). }
  14. { }
  15. { Portions created by Petr Vones are }
  16. { Copyright (C) 2000 Petr Vones }
  17. { }
  18. { Obtained through: }
  19. { }
  20. { Joint Endeavour of Delphi Innovators (Project JEDI) }
  21. { }
  22. { You may retrieve the latest version of this file at the Project }
  23. { JEDI home page, located at http://delphi-jedi.org }
  24. { }
  25. { The contents of this file are used with permission, subject to }
  26. { the Mozilla Public License Version 1.1 (the "License"); you may }
  27. { not use this file except in compliance with the License. You may }
  28. { obtain a copy of the License at }
  29. { http://www.mozilla.org/MPL/MPL-1.1.html }
  30. { }
  31. { Software distributed under the License is distributed on an }
  32. { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
  33. { implied. See the License for the specific language governing }
  34. { rights and limitations under the License. }
  35. { }
  36. {******************************************************************}
  37. unit WabCode;
  38. interface
  39. uses
  40. Windows, ActiveX;
  41. {$I WAB.INC}
  42. {$ALIGN ON}
  43. {$MINENUMSIZE 4}
  44. {$WEAKPACKAGEUNIT}
  45. (*$HPPEMIT '#include <wabcode.h>'*)
  46. (*$HPPEMIT '#include <objerror.h>'*)
  47. {*
  48. * WAB Status codes follow the style of OLE 2.0 sCodes as defined in the
  49. * OLE 2.0 Programmer's Reference and header file scode.h (Windows 3.x)
  50. * or objerror.h (Windows NT 3.5 and Windows 95).
  51. *
  52. */
  53. /* On Windows 3.x, status codes have 32-bit values as follows:
  54. *
  55. * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  56. * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  57. * +-+---------------------+-------+-------------------------------+
  58. * |S| Context | Facil | Code |
  59. * +-+---------------------+-------+-------------------------------+
  60. *
  61. * where
  62. *
  63. * S - is the severity code
  64. *
  65. * 0 - SEVERITY_SUCCESS
  66. * 1 - SEVERITY_ERROR
  67. *
  68. * Context - context info
  69. *
  70. * Facility - is the facility code
  71. *
  72. * 0x0 - FACILITY_NULL generally useful errors ([SE]_*)
  73. * 0x1 - FACILITY_RPC remote procedure call errors (RPC_E_*)
  74. * 0x2 - FACILITY_DISPATCH late binding dispatch errors
  75. * 0x3 - FACILITY_STORAGE storage errors (STG_E_*)
  76. * 0x4 - FACILITY_ITF interface-specific errors
  77. *
  78. * Code - is the facility's status code
  79. *
  80. *
  81. *}
  82. {*
  83. * On Windows NT 3.5 and Windows 95, scodes are 32-bit values
  84. * laid out as follows:
  85. *
  86. * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  87. * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  88. * +-+-+-+-+-+---------------------+-------------------------------+
  89. * |S|R|C|N|r| Facility | Code |
  90. * +-+-+-+-+-+---------------------+-------------------------------+
  91. *
  92. * where
  93. *
  94. * S - Severity - indicates success/fail
  95. *
  96. * 0 - Success
  97. * 1 - Fail (COERROR)
  98. *
  99. * R - reserved portion of the facility code, corresponds to NT's
  100. * second severity bit.
  101. *
  102. * C - reserved portion of the facility code, corresponds to NT's
  103. * C field.
  104. *
  105. * N - reserved portion of the facility code. Used to indicate a
  106. * mapped NT status value.
  107. *
  108. * r - reserved portion of the facility code. Reserved for internal
  109. * use. Used to indicate HRESULT values that are not status
  110. * values, but are instead message ids for display strings.
  111. *
  112. * Facility - is the facility code
  113. * FACILITY_NULL 0x0
  114. * FACILITY_RPC 0x1
  115. * FACILITY_DISPATCH 0x2
  116. * FACILITY_STORAGE 0x3
  117. * FACILITY_ITF 0x4
  118. * FACILITY_WIN32 0x7
  119. * FACILITY_WINDOWS 0x8
  120. *
  121. * Code - is the facility's status code
  122. *
  123. *}
  124. { * We can't use OLE 2.0 macros to build sCodes because the definition has
  125. * changed and we wish to conform to the new definition.
  126. }
  127. function MAKE_MAPI_SCODE(sev,fac,code: DWORD): SCODE;
  128. {$EXTERNALSYM MAKE_MAPI_SCODE}
  129. { The following two macros are used to build OLE 2.0 style sCodes }
  130. function MAKE_MAPI_E(err: DWORD): SCODE;
  131. {$EXTERNALSYM MAKE_MAPI_E}
  132. function MAKE_MAPI_S(warn: DWORD): SCODE;
  133. {$EXTERNALSYM MAKE_MAPI_S}
  134. const
  135. SUCCESS_SUCCESS = 0;
  136. {$EXTERNALSYM SUCCESS_SUCCESS}
  137. { General errors (used by more than one WAB object) }
  138. MAPI_E_CALL_FAILED = E_FAIL;
  139. {$EXTERNALSYM MAPI_E_CALL_FAILED}
  140. MAPI_E_NOT_ENOUGH_MEMORY = E_OUTOFMEMORY;
  141. {$EXTERNALSYM MAPI_E_NOT_ENOUGH_MEMORY}
  142. MAPI_E_INVALID_PARAMETER = E_INVALIDARG;
  143. {$EXTERNALSYM MAPI_E_INVALID_PARAMETER}
  144. MAPI_E_INTERFACE_NOT_SUPPORTED = E_NOINTERFACE;
  145. {$EXTERNALSYM MAPI_E_INTERFACE_NOT_SUPPORTED}
  146. MAPI_E_NO_ACCESS = E_ACCESSDENIED;
  147. {$EXTERNALSYM MAPI_E_NO_ACCESS}
  148. MAPI_E_NO_SUPPORT = (1 shl 31 or FACILITY_ITF shl 16 or $102);
  149. {$EXTERNALSYM MAPI_E_NO_SUPPORT}
  150. MAPI_E_BAD_CHARWIDTH = (1 shl 31 or FACILITY_ITF shl 16 or $103);
  151. {$EXTERNALSYM MAPI_E_BAD_CHARWIDTH}
  152. MAPI_E_STRING_TOO_LONG = (1 shl 31 or FACILITY_ITF shl 16 or $105);
  153. {$EXTERNALSYM MAPI_E_STRING_TOO_LONG}
  154. MAPI_E_UNKNOWN_FLAGS = (1 shl 31 or FACILITY_ITF shl 16 or $106);
  155. {$EXTERNALSYM MAPI_E_UNKNOWN_FLAGS}
  156. MAPI_E_INVALID_ENTRYID = (1 shl 31 or FACILITY_ITF shl 16 or $107);
  157. {$EXTERNALSYM MAPI_E_INVALID_ENTRYID}
  158. MAPI_E_INVALID_OBJECT = (1 shl 31 or FACILITY_ITF shl 16 or $108);
  159. {$EXTERNALSYM MAPI_E_INVALID_OBJECT}
  160. MAPI_E_OBJECT_CHANGED = (1 shl 31 or FACILITY_ITF shl 16 or $109);
  161. {$EXTERNALSYM MAPI_E_OBJECT_CHANGED}
  162. MAPI_E_OBJECT_DELETED = (1 shl 31 or FACILITY_ITF shl 16 or $10A);
  163. {$EXTERNALSYM MAPI_E_OBJECT_DELETED}
  164. MAPI_E_BUSY = (1 shl 31 or FACILITY_ITF shl 16 or $10B);
  165. {$EXTERNALSYM MAPI_E_BUSY}
  166. MAPI_E_NOT_ENOUGH_DISK = (1 shl 31 or FACILITY_ITF shl 16 or $10D);
  167. {$EXTERNALSYM MAPI_E_NOT_ENOUGH_DISK}
  168. MAPI_E_NOT_ENOUGH_RESOURCES = (1 shl 31 or FACILITY_ITF shl 16 or $10E);
  169. {$EXTERNALSYM MAPI_E_NOT_ENOUGH_RESOURCES}
  170. MAPI_E_NOT_FOUND = (1 shl 31 or FACILITY_ITF shl 16 or $10F);
  171. {$EXTERNALSYM MAPI_E_NOT_FOUND}
  172. MAPI_E_VERSION = (1 shl 31 or FACILITY_ITF shl 16 or $110);
  173. {$EXTERNALSYM MAPI_E_VERSION}
  174. MAPI_E_LOGON_FAILED = (1 shl 31 or FACILITY_ITF shl 16 or $111);
  175. {$EXTERNALSYM MAPI_E_LOGON_FAILED}
  176. MAPI_E_SESSION_LIMIT = (1 shl 31 or FACILITY_ITF shl 16 or $112);
  177. {$EXTERNALSYM MAPI_E_SESSION_LIMIT}
  178. MAPI_E_USER_CANCEL = (1 shl 31 or FACILITY_ITF shl 16 or $113);
  179. {$EXTERNALSYM MAPI_E_USER_CANCEL}
  180. MAPI_E_UNABLE_TO_ABORT = (1 shl 31 or FACILITY_ITF shl 16 or $114);
  181. {$EXTERNALSYM MAPI_E_UNABLE_TO_ABORT}
  182. MAPI_E_NETWORK_ERROR = (1 shl 31 or FACILITY_ITF shl 16 or $115);
  183. {$EXTERNALSYM MAPI_E_NETWORK_ERROR}
  184. MAPI_E_DISK_ERROR = (1 shl 31 or FACILITY_ITF shl 16 or $116);
  185. {$EXTERNALSYM MAPI_E_DISK_ERROR}
  186. MAPI_E_TOO_COMPLEX = (1 shl 31 or FACILITY_ITF shl 16 or $117);
  187. {$EXTERNALSYM MAPI_E_TOO_COMPLEX}
  188. MAPI_E_BAD_COLUMN = (1 shl 31 or FACILITY_ITF shl 16 or $118);
  189. {$EXTERNALSYM MAPI_E_BAD_COLUMN}
  190. MAPI_E_EXTENDED_ERROR = (1 shl 31 or FACILITY_ITF shl 16 or $119);
  191. {$EXTERNALSYM MAPI_E_EXTENDED_ERROR}
  192. MAPI_E_COMPUTED = (1 shl 31 or FACILITY_ITF shl 16 or $11A);
  193. {$EXTERNALSYM MAPI_E_COMPUTED}
  194. MAPI_E_CORRUPT_DATA = (1 shl 31 or FACILITY_ITF shl 16 or $11B);
  195. {$EXTERNALSYM MAPI_E_CORRUPT_DATA}
  196. MAPI_E_UNCONFIGURED = (1 shl 31 or FACILITY_ITF shl 16 or $11C);
  197. {$EXTERNALSYM MAPI_E_UNCONFIGURED}
  198. MAPI_E_FAILONEPROVIDER = (1 shl 31 or FACILITY_ITF shl 16 or $11D);
  199. {$EXTERNALSYM MAPI_E_FAILONEPROVIDER}
  200. { WAB base function and status object specific errors and warnings }
  201. MAPI_E_END_OF_SESSION = (1 shl 31 or FACILITY_ITF shl 16 or $200);
  202. {$EXTERNALSYM MAPI_E_END_OF_SESSION}
  203. MAPI_E_UNKNOWN_ENTRYID = (1 shl 31 or FACILITY_ITF shl 16 or $201);
  204. {$EXTERNALSYM MAPI_E_UNKNOWN_ENTRYID}
  205. MAPI_E_MISSING_REQUIRED_COLUMN = (1 shl 31 or FACILITY_ITF shl 16 or $202);
  206. {$EXTERNALSYM MAPI_E_MISSING_REQUIRED_COLUMN}
  207. MAPI_W_NO_SERVICE = (FACILITY_ITF shl 16 or $203);
  208. {$EXTERNALSYM MAPI_W_NO_SERVICE}
  209. { Property specific errors and warnings }
  210. MAPI_E_BAD_VALUE = (1 shl 31 or FACILITY_ITF shl 16 or $301);
  211. {$EXTERNALSYM MAPI_E_BAD_VALUE}
  212. MAPI_E_INVALID_TYPE = (1 shl 31 or FACILITY_ITF shl 16 or $302);
  213. {$EXTERNALSYM MAPI_E_INVALID_TYPE}
  214. MAPI_E_TYPE_NO_SUPPORT = (1 shl 31 or FACILITY_ITF shl 16 or $303);
  215. {$EXTERNALSYM MAPI_E_TYPE_NO_SUPPORT}
  216. MAPI_E_UNEXPECTED_TYPE = (1 shl 31 or FACILITY_ITF shl 16 or $304);
  217. {$EXTERNALSYM MAPI_E_UNEXPECTED_TYPE}
  218. MAPI_E_TOO_BIG = (1 shl 31 or FACILITY_ITF shl 16 or $305);
  219. {$EXTERNALSYM MAPI_E_TOO_BIG}
  220. MAPI_E_DECLINE_COPY = (1 shl 31 or FACILITY_ITF shl 16 or $306);
  221. {$EXTERNALSYM MAPI_E_DECLINE_COPY}
  222. MAPI_E_UNEXPECTED_ID = (1 shl 31 or FACILITY_ITF shl 16 or $307);
  223. {$EXTERNALSYM MAPI_E_UNEXPECTED_ID}
  224. MAPI_W_ERRORS_RETURNED = (FACILITY_ITF shl 16 or $380);
  225. {$EXTERNALSYM MAPI_W_ERRORS_RETURNED}
  226. { Table specific errors and warnings }
  227. MAPI_E_UNABLE_TO_COMPLETE = (1 shl 31 or FACILITY_ITF shl 16 or $400);
  228. {$EXTERNALSYM MAPI_E_UNABLE_TO_COMPLETE}
  229. MAPI_E_TIMEOUT = (1 shl 31 or FACILITY_ITF shl 16 or $401);
  230. {$EXTERNALSYM MAPI_E_TIMEOUT}
  231. MAPI_E_TABLE_EMPTY = (1 shl 31 or FACILITY_ITF shl 16 or $402);
  232. {$EXTERNALSYM MAPI_E_TABLE_EMPTY}
  233. MAPI_E_TABLE_TOO_BIG = (1 shl 31 or FACILITY_ITF shl 16 or $403);
  234. {$EXTERNALSYM MAPI_E_TABLE_TOO_BIG}
  235. MAPI_E_INVALID_BOOKMARK = (1 shl 31 or FACILITY_ITF shl 16 or $405);
  236. {$EXTERNALSYM MAPI_E_INVALID_BOOKMARK}
  237. MAPI_W_POSITION_CHANGED = (FACILITY_ITF shl 16 or $481);
  238. {$EXTERNALSYM MAPI_W_POSITION_CHANGED}
  239. MAPI_W_APPROX_COUNT = (FACILITY_ITF shl 16 or $482);
  240. {$EXTERNALSYM MAPI_W_APPROX_COUNT}
  241. MAPI_W_PARTIAL_COMPLETION = (FACILITY_ITF shl 16 or $680);
  242. {$EXTERNALSYM MAPI_W_PARTIAL_COMPLETION}
  243. { Address Book specific errors and warnings }
  244. MAPI_E_AMBIGUOUS_RECIP = (1 shl 31 or FACILITY_ITF shl 16 or $700);
  245. {$EXTERNALSYM MAPI_E_AMBIGUOUS_RECIP}
  246. { Miscellaneous errors }
  247. MAPI_E_COLLISION = (1 shl 31 or FACILITY_ITF shl 16 or $604);
  248. {$EXTERNALSYM MAPI_E_COLLISION}
  249. MAPI_E_NOT_INITIALIZED = (1 shl 31 or FACILITY_ITF shl 16 or $605);
  250. {$EXTERNALSYM MAPI_E_NOT_INITIALIZED}
  251. MAPI_E_FOLDER_CYCLE = (1 shl 31 or FACILITY_ITF shl 16 or $60B);
  252. {$EXTERNALSYM MAPI_E_FOLDER_CYCLE}
  253. { The range 0x0800 to 0x08FF is reserved }
  254. {* We expect these to eventually be defined by OLE, but for now,
  255. * here they are. When OLE defines them they can be much more
  256. * efficient than these, but these are "proper" and don't make
  257. * use of any hidden tricks.
  258. }
  259. function HR_SUCCEEDED(_hr: HRESULT): Boolean;
  260. {$EXTERNALSYM HR_SUCCEEDED}
  261. function HR_FAILED(_hr: HRESULT): Boolean;
  262. {$EXTERNALSYM HR_FAILED}
  263. implementation
  264. function MAKE_MAPI_SCODE(sev,fac,code: DWORD): SCODE;
  265. begin
  266. Result := sev shl 31 or fac shl 16 or code;
  267. end;
  268. function MAKE_MAPI_E(err: DWORD): SCODE;
  269. begin
  270. Result := MAKE_MAPI_SCODE(1, FACILITY_ITF, err);
  271. end;
  272. function MAKE_MAPI_S(warn: DWORD): SCODE;
  273. begin
  274. Result := MAKE_MAPI_SCODE(0, FACILITY_ITF, warn);
  275. end;
  276. function HR_SUCCEEDED(_hr: HRESULT): Boolean;
  277. begin
  278. Result := Succeeded(_hr);
  279. end;
  280. function HR_FAILED(_hr: HRESULT): Boolean;
  281. begin
  282. Result := Failed(_hr);
  283. end;
  284. end.