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.

462 lines
11 KiB

  1. /*
  2. * _ M A P I U . H
  3. *
  4. * Non-public MACROs and FUNCTIONs which may be used by MAPI
  5. *
  6. * Used in conjunction with routines found in MAPIU.DLL.
  7. *
  8. * Copyright 1992-93 Microsoft Corporation. All Rights Reserved.
  9. */
  10. #ifndef _MAPIU_H
  11. #define _MAPIU_H
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. extern CRITICAL_SECTION csUnkobjInit;
  16. /* Macros provided by MAPIU
  17. */
  18. #ifndef CharSizeOf
  19. #define CharSizeOf(x) (sizeof(x) / sizeof(x[0]))
  20. #endif
  21. // Alignment
  22. #define AlignN(n, x) (((x)+(1<<(n))-1) & ~((1<<(n))-1))
  23. #define Align2(x) AlignN(1,(x))
  24. #define Align4(x) AlignN(2,(x))
  25. #define Align8(x) AlignN(3,(x))
  26. #if defined (_AMD64_) || defined (_IA64_)
  27. #define AlignNatural(cb) Align8(cb)
  28. #elif defined (WIN32)
  29. #define AlignNatural(cb) Align4(cb)
  30. #else // defined (WIN16)
  31. #define AlignNatural(cb) Align2(cb)
  32. #endif
  33. #define FIsAligned(p) (AlignNatural((ULONG_PTR)((LPVOID)p)) == (ULONG_PTR)((LPVOID)p))
  34. #define FIsAlignedCb(cb) (AlignNatural((ULONG_PTR)(cb)) == (ULONG_PTR)(cb))
  35. /* Prototypes for private math functions
  36. */
  37. STDAPI_(DWORD)
  38. DwDivFtDw( FILETIME ftDividend, DWORD dwDivisor);
  39. VOID
  40. VSzFromIDS(ULONG ulIDS, UINT uncchBuffer, LPWSTR lpszBuffer, ULONG ulFlags);
  41. /* Prototype for LoadString wrapper
  42. * Utility to allocate memory and loadstring and string IDS, ANSI/UNICODE.
  43. */
  44. #define MAX_CCH_IDS 256
  45. SCODE ScStringFromIDS( LPALLOCATEBUFFER lpMapiAllocBuffer, ULONG ulFlags, UINT ids,
  46. LPTSTR * lppszIDS );
  47. /* Prototypes for Message and Dialog Box utilities.
  48. */
  49. SCODE
  50. ScMessageBoxIDS( ULONG ulUIParam,
  51. UINT idsCaption,
  52. UINT idsMessage,
  53. UINT uMBType);
  54. /* Prototypes for MAPI status utilities.
  55. */
  56. BOOL
  57. FProfileLoggedOn( LPSTR szProfileName);
  58. /* Prototypes for functions used to validate complex parameters.
  59. */
  60. #ifndef __cplusplus
  61. #define FBadIfacePtr(param, iface) \
  62. ( IsBadReadPtr((param), sizeof(iface)) \
  63. || IsBadReadPtr((param)->lpVtbl, sizeof(iface##Vtbl)))
  64. #else
  65. #define FBadIfacePtr(param, iface) (FALSE)
  66. #endif
  67. /*
  68. * FBadDelPTA
  69. *
  70. * Returns TRUE if the given Prop Tag Array is readable and contains only
  71. * prop tags which are valid for a DeleteProps (or related) call.
  72. */
  73. STDAPI_(BOOL)
  74. FBadDelPTA(LPSPropTagArray lpPropTagArray);
  75. #ifndef WIN16 // WIN16 C compiler doesn't support INLINE functions.
  76. /*
  77. * IListedPropID
  78. *
  79. * Purpose
  80. * If a tag with ID == PROP_ID(ulPropTag) is listed in lptaga then
  81. * the index of tag is returned. If the tag is not in lptaga then
  82. * -1 is returned.
  83. *
  84. * Arguments
  85. * ulPropTag Property tag to locate.
  86. * lptaga Property tag array to search.
  87. *
  88. * Returns TRUE or FALSE
  89. */
  90. _inline LONG_PTR
  91. IListedPropID( ULONG ulPropTag,
  92. LPSPropTagArray lptaga)
  93. {
  94. UNALIGNED ULONG FAR *lpulPTag;
  95. /* No tag is contained in a NULL list of tags.
  96. */
  97. if (!lptaga)
  98. {
  99. return -1;
  100. }
  101. /* Mutate ulPropTag to just a PROP_ID.
  102. */
  103. ulPropTag = PROP_ID(ulPropTag);
  104. for ( lpulPTag = lptaga->aulPropTag + lptaga->cValues
  105. ; --lpulPTag >= lptaga->aulPropTag
  106. ; )
  107. {
  108. /* Compare PROP_ID's.
  109. */
  110. if (PROP_ID(*lpulPTag) == ulPropTag)
  111. {
  112. return (lpulPTag - lptaga->aulPropTag);
  113. }
  114. }
  115. return -1;
  116. }
  117. /*
  118. * FListedPropID
  119. *
  120. * Purpose
  121. * Determine if a tag with ID == PROP_ID(ulPropTag) is listed in lptaga.
  122. *
  123. * Arguments
  124. * ulPropTag Property tag to locate.
  125. * lptaga Property tag array to search.
  126. *
  127. * Returns TRUE or FALSE
  128. */
  129. _inline BOOL
  130. FListedPropID( ULONG ulPropTag,
  131. LPSPropTagArray lptaga)
  132. {
  133. UNALIGNED ULONG FAR *lpulPTag;
  134. /* No tag is contained in a NULL list of tags.
  135. */
  136. if (!lptaga)
  137. {
  138. return FALSE;
  139. }
  140. /* Mutate ulPropTag to just a PROP_ID.
  141. */
  142. ulPropTag = PROP_ID(ulPropTag);
  143. for ( lpulPTag = lptaga->aulPropTag + lptaga->cValues
  144. ; --lpulPTag >= lptaga->aulPropTag
  145. ; )
  146. {
  147. /* Compare PROP_ID's.
  148. */
  149. if (PROP_ID(*lpulPTag) == ulPropTag)
  150. {
  151. return TRUE;
  152. }
  153. }
  154. return FALSE;
  155. }
  156. /*
  157. * FListedPropTAG
  158. *
  159. * Purpose
  160. * Determine if a the given ulPropTag is listed in lptaga.
  161. *
  162. * Arguments
  163. * ulPropTag Property tag to locate.
  164. * lptaga Property tag array to search.
  165. *
  166. * Returns TRUE or FALSE
  167. */
  168. _inline BOOL
  169. FListedPropTAG( ULONG ulPropTag,
  170. LPSPropTagArray lptaga)
  171. {
  172. UNALIGNED ULONG FAR *lpulPTag;
  173. /* No tag is contained in a NULL list of tags.
  174. */
  175. if (!lptaga)
  176. {
  177. return FALSE;
  178. }
  179. /* Compare the entire prop tag to be sure both ID and TYPE match
  180. */
  181. for ( lpulPTag = lptaga->aulPropTag + lptaga->cValues
  182. ; --lpulPTag >= lptaga->aulPropTag
  183. ; )
  184. {
  185. /* Compare PROP_ID's.
  186. */
  187. if (PROP_ID(*lpulPTag) == ulPropTag)
  188. {
  189. return TRUE;
  190. }
  191. }
  192. return FALSE;
  193. }
  194. /*
  195. * AddProblem
  196. *
  197. * Purpose
  198. * Adds a problem to the next available entry of a pre-allocated problem
  199. * array.
  200. * The pre-allocated problem array must be big enough to have another
  201. * problem added. The caller is responsible for making sure this is
  202. * true.
  203. *
  204. * Arguments
  205. * lpProblems Pointer to pre-allocated probelem array.
  206. * ulIndex Index into prop tag/value array of the problem property.
  207. * ulPropTag Prop tag of property which had the problem.
  208. * scode Error code to list for the property.
  209. *
  210. * Returns TRUE or FALSE
  211. */
  212. _inline VOID
  213. AddProblem( LPSPropProblemArray lpProblems,
  214. ULONG ulIndex,
  215. ULONG ulPropTag,
  216. SCODE scode)
  217. {
  218. if (lpProblems)
  219. {
  220. Assert( !IsBadWritePtr( lpProblems->aProblem + lpProblems->cProblem
  221. , sizeof(SPropProblem)));
  222. lpProblems->aProblem[lpProblems->cProblem].ulIndex = ulIndex;
  223. lpProblems->aProblem[lpProblems->cProblem].ulPropTag = ulPropTag;
  224. lpProblems->aProblem[lpProblems->cProblem].scode = scode;
  225. lpProblems->cProblem++;
  226. }
  227. }
  228. __inline BOOL
  229. FIsExcludedIID( LPCIID lpiidToCheck, LPCIID rgiidExclude, ULONG ciidExclude)
  230. {
  231. /* Check the obvious (no exclusions).
  232. */
  233. if (!ciidExclude || !rgiidExclude)
  234. {
  235. return FALSE;
  236. }
  237. /* Check each iid in the list of exclusions.
  238. */
  239. for (; ciidExclude; rgiidExclude++, ciidExclude--)
  240. {
  241. // if (IsEqualGUID( lpiidToCheck, rgiidExclude))
  242. if (!memcmp( lpiidToCheck, rgiidExclude, sizeof(MAPIUID)))
  243. {
  244. return TRUE;
  245. }
  246. }
  247. return FALSE;
  248. }
  249. /*
  250. * Error/Warning Alert Message Boxes
  251. */
  252. int AlertIdsCtx( HWND hwnd,
  253. HINSTANCE hinst,
  254. UINT idsMsg,
  255. LPSTR szComponent,
  256. ULONG ulContext,
  257. ULONG ulLow,
  258. UINT fuStyle);
  259. __inline int
  260. AlertIds(HWND hwnd, HINSTANCE hinst, UINT idsMsg, UINT fuStyle)
  261. {
  262. return AlertIdsCtx(hwnd, hinst, idsMsg, NULL, 0, 0, fuStyle);
  263. }
  264. int AlertSzCtx( HWND hwnd,
  265. LPSTR szMsg,
  266. LPSTR szComponent,
  267. ULONG ulContext,
  268. ULONG ulLow,
  269. UINT fuStyle);
  270. __inline int
  271. AlertSz(HWND hwnd, LPSTR szMsg, UINT fuStyle)
  272. {
  273. return AlertSzCtx(hwnd, szMsg, NULL, 0, 0, fuStyle);
  274. }
  275. #else // !WIN16
  276. LONG IListedPropID( ULONG ulPropTag, LPSPropTagArray lptaga);
  277. BOOL FListedPropID( ULONG ulPropTag, LPSPropTagArray lptaga);
  278. BOOL FListedPropTAG( ULONG ulPropTag, LPSPropTagArray lptaga);
  279. VOID AddProblem( LPSPropProblemArray lpProblems, ULONG ulIndex, ULONG ulPropTag, SCODE scode);
  280. BOOL FIsExcludedIID( LPCIID lpiidToCheck, LPCIID rgiidExclude, ULONG ciidExclude);
  281. int AlertIds(HWND hwnd, HINSTANCE hinst, UINT idsMsg, UINT fuStyle);
  282. int AlertSzCtx( HWND hwnd, LPSTR szMsg, LPSTR szComponent, ULONG ulContext, ULONG ulLow, UINT fuStyle);
  283. int AlertSz(HWND hwnd, LPSTR szMsg, UINT fuStyle);
  284. #endif // !WIN16
  285. /* Encoding and decoding strings */
  286. STDAPI_(void) EncodeID(LPBYTE lpb, ULONG cb, LPTSTR lpsz);
  287. STDAPI_(BOOL) FDecodeID(LPTSTR lpsz, LPBYTE lpb, ULONG FAR *lpcb);
  288. STDAPI_(ULONG) CchOfEncoding(ULONG cb);
  289. STDAPI_(ULONG) CbOfEncoded(LPTSTR lpsz);
  290. STDAPI_(int) CchEncodedLine(int cb);
  291. /* Idle engine routines */
  292. #ifdef DEBUG
  293. /*
  294. * DumpIdleTable
  295. *
  296. * Used for debugging only. Writes information in the PGD(hftgIdle)
  297. * table to COM1.
  298. */
  299. STDAPI_(void)
  300. DumpIdleTable (void);
  301. #endif
  302. /*
  303. * FDoNextIdleTask
  304. *
  305. * Dispatches the first eligible idle function, according to
  306. * its simple scheduling algorithm.
  307. */
  308. STDAPI_(BOOL) FDoNextIdleTask (void);
  309. /* C runtime substitutes */
  310. typedef int (__cdecl FNSGNCMP)(const void FAR *lpv1, const void FAR *lpv2);
  311. typedef FNSGNCMP FAR *PFNSGNCMP;
  312. FNSGNCMP SgnCmpPadrentryByType;
  313. BOOL FRKFindSubpb(LPBYTE pbTarget, ULONG cbTarget, LPBYTE pbPattern, ULONG cbPattern);
  314. BOOL FRKFindSubpsz(LPSTR pszTarget, ULONG cbTarget, LPSTR pszPattern, ULONG cbPattern, ULONG ulFuzzyLevel);
  315. LPSTR LpszRKFindSubpsz(LPSTR pszTarget, ULONG cbTarget, LPSTR pszPattern, ULONG cbPattern, ULONG ulFuzzyLevel);
  316. STDAPI_(void) ShellSort(LPVOID lpv, UINT cv, /* qsort */
  317. LPVOID lpvT, UINT cb, PFNSGNCMP fpCmp);
  318. /* Advise list maintainence utilities */
  319. /*
  320. * Structure and functions for maintaining a list of advise sinks,
  321. * together with the keys used to release them.
  322. */
  323. typedef struct
  324. {
  325. LPMAPIADVISESINK lpAdvise;
  326. ULONG ulConnection;
  327. ULONG ulType;
  328. LPUNKNOWN lpParent;
  329. } ADVISEITEM, FAR *LPADVISEITEM;
  330. typedef struct
  331. {
  332. ULONG cItemsMac;
  333. ULONG cItemsMax;
  334. #if defined(WIN32) && !defined(MAC)
  335. CRITICAL_SECTION FAR * lpcs;
  336. #endif
  337. ADVISEITEM rgItems[1];
  338. } ADVISELIST, FAR *LPADVISELIST;
  339. #define CbNewADVISELIST(_citems) \
  340. (offsetof(ADVISELIST, rgItems) + (_citems) * sizeof(ADVISEITEM))
  341. #define CbADVISELIST(_plist) \
  342. (offsetof(ADVISELIST, rgItems) + (_plist)->cItemsMax * sizeof(ADVISEITEM))
  343. STDAPI_(SCODE)
  344. ScAddAdviseList( LPVOID lpvReserved,
  345. LPADVISELIST FAR *lppList,
  346. LPMAPIADVISESINK lpAdvise,
  347. ULONG ulConnection,
  348. ULONG ulType,
  349. LPUNKNOWN lpParent);
  350. STDAPI_(SCODE)
  351. ScDelAdviseList( LPADVISELIST lpList,
  352. ULONG ulConnection);
  353. STDAPI_(SCODE)
  354. ScFindAdviseList( LPADVISELIST lpList,
  355. ULONG ulConnection,
  356. LPADVISEITEM FAR *lppItem);
  357. STDAPI_(void)
  358. DestroyAdviseList( LPADVISELIST FAR *lppList);
  359. // prototype for routine that detects whether calling apps is
  360. // an interactive EXE or a service.
  361. #if defined( _WINNT )
  362. BOOL WINAPI IsServiceAnExe( VOID );
  363. #endif
  364. // prototype for internal routine that computes the size required
  365. // to hold a given propval array based on specified alignment
  366. SCODE ScCountPropsEx( int cprop,
  367. LPSPropValue rgprop,
  368. ULONG ulAlign,
  369. ULONG FAR *pcb );
  370. /* Option data handling routines */
  371. #ifdef MAPISPI_H
  372. STDAPI_(SCODE)
  373. ScCountOptionData(LPOPTIONDATA lpOption, ULONG FAR *lpcb);
  374. STDAPI_(SCODE)
  375. ScCopyOptionData(LPOPTIONDATA lpOption, LPVOID lpvDst, ULONG FAR *lpcb);
  376. STDAPI_(SCODE)
  377. ScRelocOptionData(LPOPTIONDATA lpOption,
  378. LPVOID lpvBaseOld, LPVOID lpvBaseNew, ULONG FAR *lpcb);
  379. #endif /* MAPISPI_H */
  380. #ifdef __cplusplus
  381. }
  382. #endif
  383. #endif // _MAPIU_H