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.

309 lines
7.1 KiB

  1. /*
  2. * _UTIL.H
  3. *
  4. * Purpose:
  5. * declarations for various useful utility functions
  6. *
  7. * Author:
  8. * alexgo (4/25/95)
  9. */
  10. #ifndef __UTIL_H__
  11. #define __UTIL_H__
  12. HGLOBAL DuplicateHGlobal( HGLOBAL hglobal );
  13. INT CountMatchingBits(const DWORD *a, const DWORD *b, INT total);
  14. HRESULT ObjectReadSiteFlags(REOBJECT * preobj);
  15. //Default values for drag scrolling
  16. //(that aren't already defined by windows).
  17. #define DEFSCROLLMAXVEL 100 //Cursor velocity above which we will not
  18. //drag scroll (units=.01 in/sec).
  19. #define DEFSCROLLVAMOUNT 50 //Vert. scroll amount per interval (units=.01 in)
  20. #define DEFSCROLLHAMOUNT 50 //Horz. scroll amount per interval (units=.01 in)
  21. //Stuff from OLESTD samples
  22. //Ole clipboard format defines.
  23. #define CF_EMBEDSOURCE "Embed Source"
  24. #define CF_EMBEDDEDOBJECT "Embedded Object"
  25. #define CF_LINKSOURCE "Link Source"
  26. #define CF_OBJECTDESCRIPTOR "Object Descriptor"
  27. #define CF_FILENAME "FileName"
  28. #define CF_OWNERLINK "OwnerLink"
  29. HRESULT OleStdSwitchDisplayAspect(
  30. LPOLEOBJECT lpOleObj,
  31. LPDWORD lpdwCurAspect,
  32. DWORD dwNewAspect,
  33. HGLOBAL hMetaPict,
  34. BOOL fDeleteOldAspect,
  35. BOOL fSetupViewAdvise,
  36. LPADVISESINK lpAdviseSink,
  37. BOOL FAR * lpfMustUpdate);
  38. LPUNKNOWN OleStdQueryInterface(
  39. LPUNKNOWN lpUnk,
  40. REFIID riid);
  41. void OleUIDrawShading(LPRECT lpRect, HDC hdc);
  42. VOID OleSaveSiteFlags(LPSTORAGE pstg, DWORD dwFlags, DWORD dwUser, DWORD dvAspect);
  43. INT AppendString( BYTE **, BYTE *, int *, int * );
  44. /****************************************************************************/
  45. /* Stabilization classes */
  46. /* These are used to stabilize objects during re-entrant calls */
  47. /****************************************************************************/
  48. //+-------------------------------------------------------------------------
  49. //
  50. // Class: CSafeRefCount
  51. //
  52. // Purpose: A concrete class for objects like the default handler to
  53. // inherit from. CSafeRefCount will keep track of reference
  54. // counts, nesting counts, and zombie states, allowing objects
  55. // to easily manage the liveness of their memory images.
  56. //
  57. // Interface:
  58. //
  59. // History: dd-mmm-yy Author Comment
  60. // 01-Aug-94 alexgo author
  61. //
  62. //--------------------------------------------------------------------------
  63. class CSafeRefCount
  64. {
  65. public:
  66. ULONG SafeAddRef();
  67. ULONG SafeRelease();
  68. ULONG IncrementNestCount();
  69. ULONG DecrementNestCount();
  70. BOOL IsZombie();
  71. CSafeRefCount();
  72. virtual ~CSafeRefCount();
  73. protected:
  74. VOID Zombie();
  75. private:
  76. ULONG m_cRefs;
  77. ULONG m_cNest;
  78. ULONG m_fInDelete :1;
  79. ULONG m_fForceZombie :1;
  80. };
  81. //+-------------------------------------------------------------------------
  82. //
  83. // Class: CStabilize
  84. //
  85. // Purpose: An instance of this class should be allocated on the
  86. // stack of every object method that makes an outgoing call.
  87. // The contstructor takes a pointer to the object's base
  88. // CSafeRefCount class.
  89. //
  90. // Interface:
  91. //
  92. // History: dd-mmm-yy Author Comment
  93. // 01-Aug-94 alexgo author
  94. //
  95. // Notes: The constructor will increment the nest count of the
  96. // object while the destructor will decrement it.
  97. //
  98. //--------------------------------------------------------------------------
  99. class CStabilize
  100. {
  101. public:
  102. inline CStabilize( CSafeRefCount *pObjSafeRefCount );
  103. inline ~CStabilize();
  104. private:
  105. CSafeRefCount * m_pObjSafeRefCount;
  106. };
  107. inline CStabilize::CStabilize( CSafeRefCount *pObjSafeRefCount )
  108. {
  109. pObjSafeRefCount->IncrementNestCount();
  110. m_pObjSafeRefCount = pObjSafeRefCount;
  111. }
  112. inline CStabilize::~CStabilize()
  113. {
  114. m_pObjSafeRefCount->DecrementNestCount();
  115. }
  116. /*
  117. * SafeReleaseAndNULL(IUnknown **ppUnk)
  118. *
  119. * Purpose:
  120. * Helper for getting stable pointers during destruction or other times
  121. *
  122. * Notes:
  123. * Not thread safe, must provide higher level synchronization.
  124. */
  125. inline void SafeReleaseAndNULL(IUnknown **ppUnk)
  126. {
  127. if (*ppUnk != NULL)
  128. {
  129. IUnknown *pUnkSave = *ppUnk;
  130. *ppUnk = NULL;
  131. pUnkSave->Release();
  132. }
  133. }
  134. BOOL FIsIconMetafilePict(HGLOBAL hmfp);
  135. HANDLE OleStdGetMetafilePictFromOleObject(
  136. LPOLEOBJECT lpOleObj,
  137. DWORD dwDrawAspect,
  138. LPSIZEL lpSizelHim,
  139. DVTARGETDEVICE FAR* ptd);
  140. HGLOBAL OleGetObjectDescriptorDataFromOleObject(
  141. LPOLEOBJECT pObj,
  142. DWORD dwAspect,
  143. POINTL ptl,
  144. LPSIZEL pszl);
  145. // Default size for stack buffer
  146. #define MAX_STACK_BUF 256
  147. /*
  148. * CTempBuf
  149. *
  150. * @class A simple temporary buffer allocator class that will allocate
  151. * buffers on the stack up to MAX_STACK_BUF and then use the
  152. * heap thereafter.
  153. */
  154. class CTempBuf
  155. {
  156. //@access Public Data
  157. public:
  158. //@cmember Constructor
  159. CTempBuf();
  160. //@cmember Destructor
  161. ~CTempBuf();
  162. //@cmember Get buffer of size cb
  163. void * GetBuf(LONG cb);
  164. //@access Private Data
  165. private:
  166. //@cmember Sets up initial state of object
  167. void Init();
  168. //@cmember Frees any buffers allocated from heap
  169. void FreeBuf();
  170. //@cmember Buffer on stack to use
  171. char _chBuf[MAX_STACK_BUF];
  172. //@cmember Pointer to buffer to use
  173. void * _pv;
  174. //@cmember Size of currently allocated buffer
  175. LONG _cb;
  176. };
  177. /*
  178. * CTempBuf::CTempBuf
  179. *
  180. * @mfunc Initialize object
  181. *
  182. */
  183. inline CTempBuf::CTempBuf()
  184. {
  185. Init();
  186. }
  187. /*
  188. * CTempBuf::~CTempBuf
  189. *
  190. * @mfunc Free any resources attached to this object
  191. *
  192. */
  193. inline CTempBuf::~CTempBuf()
  194. {
  195. FreeBuf();
  196. }
  197. /*
  198. * CTempCharBuf
  199. *
  200. * @class A wrapper for the temporary buffer allocater that returns a buffer of
  201. * char's.
  202. *
  203. * @base private | CTempBuf
  204. */
  205. class CTempWcharBuf : private CTempBuf
  206. {
  207. //@access Public Data
  208. public:
  209. //@cmember Get buffer of size cch wide characters
  210. WCHAR * GetBuf(LONG cch);
  211. };
  212. /*
  213. * CTempBuf::GetBuf
  214. *
  215. * @mfunc Get a buffer of the requested size
  216. *
  217. * @rdesc Pointer to buffer or NULL if one could not be allocated
  218. *
  219. */
  220. inline WCHAR *CTempWcharBuf::GetBuf(
  221. LONG cch) //@parm size of buffer needed in *characters*
  222. {
  223. return (WCHAR *) CTempBuf::GetBuf(cch * sizeof(WCHAR));
  224. }
  225. /*
  226. * CTempCharBuf
  227. *
  228. * @class A wrapper for the temporary buffer allocater that returns a buffer of
  229. * char's.
  230. *
  231. * @base private | CTempBuf
  232. */
  233. class CTempCharBuf : private CTempBuf
  234. {
  235. //@access Public Data
  236. public:
  237. //@cmember Get buffer of size cch characters
  238. char * GetBuf(LONG cch);
  239. };
  240. /*
  241. * CTempBuf::GetBuf
  242. *
  243. * @mfunc Get a buffer of the requested size
  244. *
  245. * @rdesc Pointer to buffer or NULL if one could not be allocated
  246. *
  247. */
  248. inline char *CTempCharBuf::GetBuf(LONG cch)
  249. {
  250. return (char *) CTempBuf::GetBuf(cch * sizeof(TCHAR));
  251. }
  252. // Author revision color table
  253. extern const COLORREF rgcrRevisions[];
  254. // Only fixed number of revision color so don't let the table overflow.
  255. #define REVMASK 7
  256. #endif // !__UTIL_H__