Source code of Windows XP (NT5)
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.

325 lines
9.7 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 struct _ULARGE_INTEGER {
  93. DWORD LowPart;
  94. DWORD HighPart;
  95. } ULARGE_INTEGER, *PULARGE_INTEGER;
  96. #define ULISet32(li, v) ((li).HighPart = 0, (li).LowPart = (v))
  97. typedef struct _LARGE_INTEGER {
  98. DWORD LowPart;
  99. LONG HighPart;
  100. } LARGE_INTEGER, *PLARGE_INTEGER;
  101. #define LISet32(li, v) ((li).HighPart = ((LONG)(v)) < 0 ? -1 : 0, (li).LowPart = (v))
  102. typedef struct tagGUID
  103. {
  104. DWORD Data1;
  105. WORD Data2;
  106. WORD Data3;
  107. BYTE Data4[8];
  108. } GUID;
  109. typedef GUID CLSID;
  110. typedef GUID IID;
  111. #define REFGUID const GUID &
  112. #define REFIID const IID &
  113. #define REFCLSID const CLSID &
  114. DECLARE_INTERFACE(IUnknown)
  115. {
  116. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  117. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  118. STDMETHOD_(ULONG,Release) (THIS) PURE;
  119. };
  120. #include "storage.h"
  121. #define S_OK 0L
  122. #define MAKE_SCODE(sev,fac,code) \
  123. ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | \
  124. ((unsigned long)(code))) )
  125. #define SEVERITY_SUCCESS 0
  126. #define SEVERITY_ERROR 1
  127. #define FACILITY_STORAGE 0x0003 // storage errors (STG_E_*)
  128. #define FACILITY_WIN32 0x0007
  129. #define FACILITY_NULL 0x0000
  130. #define FACILITY_NT_BIT 0x10000000
  131. #define HRESULT_FROM_WIN32(x) \
  132. (x ? ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) \
  133. | 0x80000000)) : 0 )
  134. #define WIN32_SCODE(err) HRESULT_FROM_WIN32(err)
  135. #define HRESULT_FROM_NT(x) ((HRESULT) ((x) | FACILITY_NT_BIT))
  136. #define S_TRUE 0L
  137. #define S_FALSE MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_NULL, 1)
  138. #define E_OUTOFMEMORY MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 2)
  139. #define E_INVALIDARG MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 3)
  140. #define E_NOINTERFACE MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 4)
  141. #define E_FAIL MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 8)
  142. #define ERROR_DIR_NOT_EMPTY 145L
  143. #define ERROR_NO_UNICODE_TRANSLATION 1113L
  144. #define SUCCEEDED(Status) ((SCODE)(Status) >= 0)
  145. #define FAILED(Status) ((SCODE)(Status)<0)
  146. //#define GetScode(hr) ((SCODE)(hr) & 0x800FFFFF)
  147. //#define ResultFromScode(sc) ((HRESULT)((SCODE)(sc) & 0x800FFFFF))
  148. #define ResultFromScode(sc) ((HRESULT) (sc))
  149. #define GetScode(hr) ((SCODE) (hr))
  150. /************** GUID's **************************************************/
  151. /* if INITGUID is defined, initialize the GUID, else declare it as extern
  152. NOTE: every EXE/DLL needs to initialize at least (and preferrably) once */
  153. #ifndef INITGUID
  154. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  155. EXTERN_C const GUID name
  156. #else
  157. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  158. EXTERN_C const GUID name; \
  159. EXTERN_C const GUID name \
  160. = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
  161. #endif /* INITGUID */
  162. #define DEFINE_OLEGUID(name, l, w1, w2) \
  163. DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
  164. DEFINE_GUID(GUID_NULL, 0L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  165. /* storage related interfaces */
  166. DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
  167. DEFINE_OLEGUID(IID_IMalloc, 0x00000002L, 0, 0);
  168. DEFINE_OLEGUID(IID_IRootStorage, 0x00000012L, 0, 0);
  169. DEFINE_OLEGUID(IID_IDfReserved1, 0x00000013L, 0, 0);
  170. DEFINE_OLEGUID(IID_IDfReserved2, 0x00000014L, 0, 0);
  171. DEFINE_OLEGUID(IID_IDfReserved3, 0x00000015L, 0, 0);
  172. DEFINE_OLEGUID(IID_ILockBytes, 0x0000000aL, 0, 0);
  173. DEFINE_OLEGUID(IID_IStorage, 0x0000000bL, 0, 0);
  174. DEFINE_OLEGUID(IID_IStream, 0x0000000cL, 0, 0);
  175. DEFINE_OLEGUID(IID_IEnumSTATSTG, 0x0000000dL, 0, 0);
  176. DEFINE_OLEGUID(IID_IPropertyStorage, 0x00000138L, 0, 0);
  177. DEFINE_OLEGUID(IID_IEnumSTATPROPSTG, 0x00000139L, 0, 0);
  178. DEFINE_OLEGUID(IID_IPropertySetStorage, 0x0000013AL, 0, 0);
  179. DEFINE_OLEGUID(IID_IEnumSTATPROPSETSTG, 0x0000013BL, 0, 0);
  180. /* The FMTID of the "SummaryInformation" property set. */
  181. DEFINE_GUID( FMTID_SummaryInformation,
  182. 0xf29f85e0, 0x4ff9, 0x1068,
  183. 0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9 );
  184. /* The FMTID of the first Section of the "DocumentSummaryInformation" property
  185. set. */
  186. DEFINE_GUID( FMTID_DocSummaryInformation,
  187. 0xd5cdd502, 0x2e9c, 0x101b,
  188. 0x93, 0x97, 0x08, 0x00, 0x2b, 0x2c, 0xf9, 0xae );
  189. /* The FMTID of the section Section of the "DocumentSummaryInformation"
  190. property set. */
  191. DEFINE_GUID( FMTID_UserDefinedProperties,
  192. 0xd5cdd505, 0x2e9c, 0x101b,
  193. 0x93, 0x97, 0x08, 0x00, 0x2b, 0x2c, 0xf9, 0xae );
  194. #define FMTID_NULL GUID_NULL
  195. /* Comparing GUIDs */
  196. EXTERN_C STDAPI_(BOOL) IsEqualGUID(REFGUID rguid1, REFGUID rguid2);
  197. #define IsEqualIID(x, y) IsEqualGUID(x, y)
  198. #define IsEqualCLSID(x, y) IsEqualGUID(x, y)
  199. #define IID_NULL GUID_NULL
  200. #define CLSID_NULL GUID_NULL
  201. // Use these to 'refer' to the formal parameters that we are not using
  202. #define UNIMPLEMENTED_PARM(x) (x)
  203. #define UNREFERENCED_PARM(x) (x)
  204. /************** Debugging Stuff *******************************************/
  205. #define DEB_ERROR 0x00000001 // exported error paths
  206. #define DEB_TRACE 0x00000004 // exported trace messages
  207. #define DEB_PROP_MAP DEB_ITRACE // 0x00000400
  208. #define DEB_IERROR 0x00000100 // internal error paths
  209. #define DEB_ITRACE 0x00000400 // internal trace messages
  210. #define DEB_ALL 0xFFFFFFFF // all traces on
  211. #if DBG == 1
  212. //
  213. // GCC versions 2.6.x (and below) has problems with inlined
  214. // variable argument macros, so we have to use non-inlined
  215. // functions for debugging.
  216. // Luckily DECLARE_INFOLEVEL is always used in a .c or .cxx file
  217. // so we can shift the function body around.
  218. //
  219. #if (__GNUC__ == 2 && __GNUC_MINOR__ <= 6)
  220. #define DECLARE_DEBUG(comp) \
  221. EXTERN_C unsigned long comp##InfoLevel; \
  222. EXTERN_C char *comp##InfoLevelString; \
  223. void comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...);
  224. #define DECLARE_INFOLEVEL(comp, level) \
  225. unsigned long comp##InfoLevel = level; \
  226. char *comp##InfoLevelString = #comp; \
  227. \
  228. void \
  229. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  230. { \
  231. va_list vstart; \
  232. va_start(vstart, pszfmt); \
  233. if (comp##InfoLevel & fDebugMask) \
  234. { \
  235. vprintf((const char *)pszfmt, vstart); \
  236. } \
  237. }
  238. #else // (__GNUC__ > 2 && __GNUC_MINOR__ <= 6)
  239. #define DECLARE_DEBUG(comp) \
  240. EXTERN_C unsigned long comp##InfoLevel; \
  241. EXTERN_C char *comp##InfoLevelString; \
  242. inline void \
  243. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  244. { \
  245. va_list vstart; \
  246. va_start(vstart, pszfmt); \
  247. if (comp##InfoLevel & fDebugMask) \
  248. { \
  249. vprintf((const char *)pszfmt, vstart); \
  250. } \
  251. }
  252. #define DECLARE_INFOLEVEL(comp, level) \
  253. unsigned long comp##InfoLevel = level; \
  254. char *comp##InfoLevelString = #comp;
  255. #endif // (__GNUC__ > 2 && __GNUC_MINOR__ <= 6)
  256. #else // DBG
  257. #define DECLARE_DEBUG(comp)
  258. #define DECLARE_INFOLEVEL(comp, level)
  259. #endif // DBG
  260. #endif // #ifndef __REF_HXX__