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