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.

331 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: ref.hxx
  7. //
  8. // Contents: Reference implementation headers
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __REF_HXX__
  12. #define __REF_HXX__
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #include <stdlib.h>
  16. #ifdef _WIN32
  17. #include <malloc.h>
  18. #include <crtdbg.h>
  19. #endif
  20. #define FARSTRUCT
  21. #define interface struct
  22. #define DECLARE_INTERFACE(iface) interface iface
  23. #define DECLARE_INTERFACE_(iface, baseiface) interface iface: public baseiface
  24. typedef long SCODE;
  25. typedef long HRESULT;
  26. #define NOERROR 0
  27. #ifdef __cplusplus
  28. #define EXTERN_C extern "C"
  29. #else
  30. #define EXTERN_C extern
  31. #endif
  32. #define PURE = 0
  33. #ifdef _MSC_VER
  34. #define STDCALL __stdcall
  35. #define STDMETHODCALLTYPE __stdcall
  36. #define EXPORTDLL _declspec(dllexport)
  37. #else // _MSC_VER
  38. #define STDCALL
  39. #define EXPORTDLL
  40. #define STDMETHODCALLTYPE
  41. #endif // _MSC_VER
  42. #define STDMETHODIMP HRESULT STDCALL
  43. #define STDMETHODIMP_(type) type STDCALL
  44. #define STDMETHOD(method) virtual HRESULT STDCALL method
  45. #define STDMETHOD_(type, method) virtual type STDCALL method
  46. #define STDAPI HRESULT EXPORTDLL STDCALL
  47. #define STDAPICALLTYPE STDCALL
  48. #define STDAPI_(type) type EXPORTDLL STDCALL
  49. #define THIS_
  50. #define THIS void
  51. #define FAR
  52. typedef int BOOL, *LPBOOL;
  53. typedef BOOL BOOLEAN;
  54. typedef unsigned char BYTE;
  55. typedef char CHAR, *PCHAR;
  56. typedef unsigned char UCHAR;
  57. typedef unsigned short WORD;
  58. typedef unsigned int UINT;
  59. typedef int INT;
  60. typedef long LONG;
  61. typedef unsigned long DWORD;
  62. typedef short SHORT;
  63. typedef unsigned short USHORT;
  64. typedef DWORD ULONG;
  65. typedef void VOID;
  66. typedef WORD WCHAR;
  67. typedef LONG NTSTATUS, *PNTSTATUS;
  68. // NOTE:
  69. // for other compilers some form of 64 bit integer support
  70. // has to be provided
  71. #ifdef __GNUC__
  72. typedef long long int LONGLONG;
  73. typedef unsigned long long int ULONGLONG;
  74. #endif
  75. #ifdef _MSC_VER
  76. typedef __int64 LONGLONG;
  77. typedef unsigned __int64 ULONGLONG;
  78. #endif
  79. typedef void *LPVOID;
  80. typedef char *LPSTR;
  81. typedef const char *LPCSTR;
  82. #define TRUE 1
  83. #define FALSE 0
  84. #ifndef _WIN32 // stuff declared in Windows but not in Unix
  85. #define _HEAP_MAXREQ 0xFFFFFFE0
  86. #define _MAX_PATH 1024
  87. #endif // _WIN32
  88. const ULONG MAX_ULONG = 0xFFFFFFFF;
  89. const USHORT USHRT_MAX = 0xFFFF;
  90. #define MAXULONG MAX_ULONG
  91. #define MAX_PATH _MAX_PATH
  92. typedef union _ULARGE_INTEGER {
  93. struct {
  94. DWORD LowPart;
  95. DWORD HighPart;
  96. } u;
  97. ULONGLONG QuadPart;
  98. } ULARGE_INTEGER, *PULARGE_INTEGER;
  99. #define ULISet32(li, v) ((li).QuadPart = (v))
  100. typedef union _LARGE_INTEGER {
  101. struct {
  102. DWORD LowPart;
  103. LONG HighPart;
  104. } u;
  105. LONGLONG QuadPart;
  106. } LARGE_INTEGER, *PLARGE_INTEGER;
  107. #define LISet32(li, v) ((li).QuadPart = (v))
  108. typedef struct tagGUID
  109. {
  110. DWORD Data1;
  111. WORD Data2;
  112. WORD Data3;
  113. BYTE Data4[8];
  114. } GUID;
  115. typedef GUID CLSID;
  116. typedef GUID IID;
  117. #define REFGUID const GUID &
  118. #define REFIID const IID &
  119. #define REFCLSID const CLSID &
  120. DECLARE_INTERFACE(IUnknown)
  121. {
  122. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  123. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  124. STDMETHOD_(ULONG,Release) (THIS) PURE;
  125. };
  126. #include "storage.h"
  127. #define S_OK 0L
  128. #define MAKE_SCODE(sev,fac,code) \
  129. ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | \
  130. ((unsigned long)(code))) )
  131. #define SEVERITY_SUCCESS 0
  132. #define SEVERITY_ERROR 1
  133. #define FACILITY_STORAGE 0x0003 // storage errors (STG_E_*)
  134. #define FACILITY_WIN32 0x0007
  135. #define FACILITY_NULL 0x0000
  136. #define FACILITY_NT_BIT 0x10000000
  137. #define HRESULT_FROM_WIN32(x) \
  138. (x ? ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) \
  139. | 0x80000000)) : 0 )
  140. #define WIN32_SCODE(err) HRESULT_FROM_WIN32(err)
  141. #define HRESULT_FROM_NT(x) ((HRESULT) ((x) | FACILITY_NT_BIT))
  142. #define S_TRUE 0L
  143. #define S_FALSE MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_NULL, 1)
  144. #define E_OUTOFMEMORY MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 2)
  145. #define E_INVALIDARG MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 3)
  146. #define E_NOINTERFACE MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 4)
  147. #define E_FAIL MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 8)
  148. #define ERROR_DIR_NOT_EMPTY 145L
  149. #define ERROR_NO_UNICODE_TRANSLATION 1113L
  150. #define SUCCEEDED(Status) ((SCODE)(Status) >= 0)
  151. #define FAILED(Status) ((SCODE)(Status)<0)
  152. //#define GetScode(hr) ((SCODE)(hr) & 0x800FFFFF)
  153. //#define ResultFromScode(sc) ((HRESULT)((SCODE)(sc) & 0x800FFFFF))
  154. #define ResultFromScode(sc) ((HRESULT) (sc))
  155. #define GetScode(hr) ((SCODE) (hr))
  156. /************** GUID's **************************************************/
  157. /* if INITGUID is defined, initialize the GUID, else declare it as extern
  158. NOTE: every EXE/DLL needs to initialize at least (and preferrably) once */
  159. #ifndef INITGUID
  160. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  161. EXTERN_C const GUID name
  162. #else
  163. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  164. EXTERN_C const GUID name; \
  165. EXTERN_C const GUID name \
  166. = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
  167. #endif /* INITGUID */
  168. #define DEFINE_OLEGUID(name, l, w1, w2) \
  169. DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
  170. DEFINE_GUID(GUID_NULL, 0L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  171. /* storage related interfaces */
  172. DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
  173. DEFINE_OLEGUID(IID_IMalloc, 0x00000002L, 0, 0);
  174. DEFINE_OLEGUID(IID_IRootStorage, 0x00000012L, 0, 0);
  175. DEFINE_OLEGUID(IID_IDfReserved1, 0x00000013L, 0, 0);
  176. DEFINE_OLEGUID(IID_IDfReserved2, 0x00000014L, 0, 0);
  177. DEFINE_OLEGUID(IID_IDfReserved3, 0x00000015L, 0, 0);
  178. DEFINE_OLEGUID(IID_ILockBytes, 0x0000000aL, 0, 0);
  179. DEFINE_OLEGUID(IID_IStorage, 0x0000000bL, 0, 0);
  180. DEFINE_OLEGUID(IID_IStream, 0x0000000cL, 0, 0);
  181. DEFINE_OLEGUID(IID_IEnumSTATSTG, 0x0000000dL, 0, 0);
  182. DEFINE_OLEGUID(IID_IPropertyStorage, 0x00000138L, 0, 0);
  183. DEFINE_OLEGUID(IID_IEnumSTATPROPSTG, 0x00000139L, 0, 0);
  184. DEFINE_OLEGUID(IID_IPropertySetStorage, 0x0000013AL, 0, 0);
  185. DEFINE_OLEGUID(IID_IEnumSTATPROPSETSTG, 0x0000013BL, 0, 0);
  186. /* The FMTID of the "SummaryInformation" property set. */
  187. DEFINE_GUID( FMTID_SummaryInformation,
  188. 0xf29f85e0, 0x4ff9, 0x1068,
  189. 0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 );
  190. /* The FMTID of the first Section of the "DocumentSummaryInformation" property
  191. set. */
  192. DEFINE_GUID( FMTID_DocSummaryInformation,
  193. 0xd5cdd502, 0x2e9c, 0x101b,
  194. 0x93, 0x97, 0x08, 0x00, 0x2b, 0x2c, 0xf9, 0xae );
  195. /* The FMTID of the section Section of the "DocumentSummaryInformation"
  196. property set. */
  197. DEFINE_GUID( FMTID_UserDefinedProperties,
  198. 0xd5cdd505, 0x2e9c, 0x101b,
  199. 0x93, 0x97, 0x08, 0x00, 0x2b, 0x2c, 0xf9, 0xae );
  200. #define FMTID_NULL GUID_NULL
  201. /* Comparing GUIDs */
  202. EXTERN_C STDAPI_(BOOL) IsEqualGUID(REFGUID rguid1, REFGUID rguid2);
  203. #define IsEqualIID(x, y) IsEqualGUID(x, y)
  204. #define IsEqualCLSID(x, y) IsEqualGUID(x, y)
  205. #define IID_NULL GUID_NULL
  206. #define CLSID_NULL GUID_NULL
  207. // Use these to 'refer' to the formal parameters that we are not using
  208. #define UNIMPLEMENTED_PARM(x) (x)
  209. #define UNREFERENCED_PARM(x) (x)
  210. /************** Debugging Stuff *******************************************/
  211. #define DEB_ERROR 0x00000001 // exported error paths
  212. #define DEB_TRACE 0x00000004 // exported trace messages
  213. #define DEB_PROP_MAP DEB_ITRACE // 0x00000400
  214. #define DEB_IERROR 0x00000100 // internal error paths
  215. #define DEB_ITRACE 0x00000400 // internal trace messages
  216. #define DEB_ALL 0xFFFFFFFF // all traces on
  217. #if DBG == 1
  218. //
  219. // GCC versions 2.6.x (and below) has problems with inlined
  220. // variable argument macros, so we have to use non-inlined
  221. // functions for debugging.
  222. // Luckily DECLARE_INFOLEVEL is always used in a .c or .cxx file
  223. // so we can shift the function body around.
  224. //
  225. #if (__GNUC__ == 2 && __GNUC_MINOR__ <= 6)
  226. #define DECLARE_DEBUG(comp) \
  227. EXTERN_C unsigned long comp##InfoLevel; \
  228. EXTERN_C char *comp##InfoLevelString; \
  229. void comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...);
  230. #define DECLARE_INFOLEVEL(comp, level) \
  231. unsigned long comp##InfoLevel = level; \
  232. char *comp##InfoLevelString = #comp; \
  233. \
  234. void \
  235. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  236. { \
  237. va_list vstart; \
  238. va_start(vstart, pszfmt); \
  239. if (comp##InfoLevel & fDebugMask) \
  240. { \
  241. vprintf((const char *)pszfmt, vstart); \
  242. } \
  243. }
  244. #else // (__GNUC__ > 2 && __GNUC_MINOR__ <= 6)
  245. #define DECLARE_DEBUG(comp) \
  246. EXTERN_C unsigned long comp##InfoLevel; \
  247. EXTERN_C char *comp##InfoLevelString; \
  248. inline void \
  249. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  250. { \
  251. va_list vstart; \
  252. va_start(vstart, pszfmt); \
  253. if (comp##InfoLevel & fDebugMask) \
  254. { \
  255. vprintf((const char *)pszfmt, vstart); \
  256. } \
  257. }
  258. #define DECLARE_INFOLEVEL(comp, level) \
  259. unsigned long comp##InfoLevel = level; \
  260. char *comp##InfoLevelString = #comp;
  261. #endif // (__GNUC__ > 2 && __GNUC_MINOR__ <= 6)
  262. #else // DBG
  263. #define DECLARE_DEBUG(comp)
  264. #define DECLARE_INFOLEVEL(comp, level)
  265. #endif // DBG
  266. #endif // #ifndef __REF_HXX__