• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // MyWindows.h
2 
3 #ifdef Z7_DEFINE_GUID
4 #undef Z7_DEFINE_GUID
5 #endif
6 
7 #ifdef INITGUID
8   #define Z7_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
9     EXTERN_C const GUID name; \
10     EXTERN_C const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
11 #else
12   #define Z7_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
13     EXTERN_C const GUID name
14 #endif
15 
16 
17 #ifndef ZIP7_INC_MY_WINDOWS_H
18 #define ZIP7_INC_MY_WINDOWS_H
19 
20 #ifdef _WIN32
21 
22 #include "../../C/7zWindows.h"
23 
24 #else // _WIN32
25 
26 #include <stddef.h> // for wchar_t
27 #include <string.h>
28 // #include <stdint.h> // for uintptr_t
29 
30 #include "../../C/7zTypes.h"
31 #include "MyGuidDef.h"
32 
33 // WINAPI is __stdcall in Windows-MSVC in windef.h
34 #define WINAPI
35 
36 typedef char CHAR;
37 typedef unsigned char UCHAR;
38 
39 #undef BYTE
40 typedef unsigned char BYTE;
41 
42 typedef short SHORT;
43 typedef unsigned short USHORT;
44 
45 #undef WORD
46 typedef unsigned short WORD;
47 typedef short VARIANT_BOOL;
48 
49 #define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff))
50 #define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16))
51 
52 // MS uses long for BOOL, but long is 32-bit in MS. So we use int.
53 // typedef long BOOL;
54 typedef int BOOL;
55 
56 #ifndef FALSE
57   #define FALSE 0
58   #define TRUE 1
59 #endif
60 
61 // typedef size_t ULONG_PTR;
62 // typedef size_t DWORD_PTR;
63 // typedef uintptr_t UINT_PTR;
64 // typedef ptrdiff_t UINT_PTR;
65 
66 typedef Int64 LONGLONG;
67 typedef UInt64 ULONGLONG;
68 
69 typedef struct _LARGE_INTEGER { LONGLONG QuadPart; } LARGE_INTEGER;
70 typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart; } ULARGE_INTEGER;
71 
72 typedef const CHAR *LPCSTR;
73 typedef CHAR TCHAR;
74 typedef const TCHAR *LPCTSTR;
75 typedef wchar_t WCHAR;
76 typedef WCHAR OLECHAR;
77 typedef const WCHAR *LPCWSTR;
78 typedef OLECHAR *BSTR;
79 typedef const OLECHAR *LPCOLESTR;
80 typedef OLECHAR *LPOLESTR;
81 
82 typedef struct _FILETIME
83 {
84   DWORD dwLowDateTime;
85   DWORD dwHighDateTime;
86 } FILETIME;
87 
88 #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
89 #define FAILED(hr)    ((HRESULT)(hr) < 0)
90 typedef ULONG PROPID;
91 typedef LONG SCODE;
92 
93 
94 #define S_OK    ((HRESULT)0x00000000L)
95 #define S_FALSE ((HRESULT)0x00000001L)
96 #define E_NOTIMPL     ((HRESULT)0x80004001L)
97 #define E_NOINTERFACE ((HRESULT)0x80004002L)
98 #define E_ABORT       ((HRESULT)0x80004004L)
99 #define E_FAIL        ((HRESULT)0x80004005L)
100 #define STG_E_INVALIDFUNCTION     ((HRESULT)0x80030001L)
101 #define CLASS_E_CLASSNOTAVAILABLE ((HRESULT)0x80040111L)
102 
103 
104 #ifdef _MSC_VER
105 #define STDMETHODCALLTYPE __stdcall
106 #define STDAPICALLTYPE    __stdcall
107 #else
108 // do we need __export here?
109 #define STDMETHODCALLTYPE
110 #define STDAPICALLTYPE
111 #endif
112 
113 #define STDAPI  EXTERN_C HRESULT STDAPICALLTYPE
114 
115 #ifndef DECLSPEC_NOTHROW
116 #define DECLSPEC_NOTHROW    Z7_DECLSPEC_NOTHROW
117 #endif
118 
119 #ifndef DECLSPEC_NOVTABLE
120 #define DECLSPEC_NOVTABLE   Z7_DECLSPEC_NOVTABLE
121 #endif
122 
123 #ifndef COM_DECLSPEC_NOTHROW
124 #ifdef COM_STDMETHOD_CAN_THROW
125   #define COM_DECLSPEC_NOTHROW
126 #else
127   #define COM_DECLSPEC_NOTHROW  DECLSPEC_NOTHROW
128 #endif
129 #endif
130 
131 #define DECLARE_INTERFACE(iface)              struct DECLSPEC_NOVTABLE iface
132 #define DECLARE_INTERFACE_(iface, baseiface)  struct DECLSPEC_NOVTABLE iface : public baseiface
133 
134 #define STDMETHOD_(t, f)  virtual COM_DECLSPEC_NOTHROW t STDMETHODCALLTYPE f
135 #define STDMETHOD(f)      STDMETHOD_(HRESULT, f)
136 #define STDMETHODIMP_(t)  COM_DECLSPEC_NOTHROW t STDMETHODCALLTYPE
137 #define STDMETHODIMP      STDMETHODIMP_(HRESULT)
138 
139 
140 #define PURE = 0
141 
142 // #define MIDL_INTERFACE(x) struct
143 
144 
145 #ifdef __cplusplus
146 
147 /*
148   p7zip and 7-Zip before v23 used virtual destructor in IUnknown,
149   if _WIN32 is not defined.
150   It used virtual destructor, because some compilers don't like virtual
151   interfaces without virtual destructor.
152   IUnknown in Windows (_WIN32) doesn't use virtual destructor in IUnknown.
153   We still can define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN here,
154   if we want to be compatible with old plugin interface of p7zip and 7-Zip before v23.
155 
156 v23:
157   In new 7-Zip v23 we try to be more compatible with original IUnknown from _WIN32.
158   So we do not define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN here,
159 */
160 // #define Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN
161 
162 #ifdef Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN
163 #if defined(__clang__)
164 #pragma GCC diagnostic ignored "-Winconsistent-missing-destructor-override"
165 #endif
166 #endif
167 
168 Z7_PURE_INTERFACES_BEGIN
169 
170 DEFINE_GUID(IID_IUnknown,
171 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
172 struct IUnknown
173 {
174   STDMETHOD(QueryInterface) (REFIID iid, void **outObject) =0;
175   STDMETHOD_(ULONG, AddRef)() =0;
176   STDMETHOD_(ULONG, Release)() =0;
177  #ifdef Z7_USE_VIRTUAL_DESTRUCTOR_IN_IUNKNOWN
~IUnknownIUnknown178   virtual ~IUnknown() {}
179  #endif
180 };
181 
182 typedef IUnknown *LPUNKNOWN;
183 
184 Z7_PURE_INTERFACES_END
185 
186 #endif // __cplusplus
187 
188 #define VARIANT_TRUE ((VARIANT_BOOL)-1)
189 #define VARIANT_FALSE ((VARIANT_BOOL)0)
190 
191 enum VARENUM
192 {
193   VT_EMPTY = 0,
194   VT_NULL = 1,
195   VT_I2 = 2,
196   VT_I4 = 3,
197   VT_R4 = 4,
198   VT_R8 = 5,
199   VT_CY = 6,
200   VT_DATE = 7,
201   VT_BSTR = 8,
202   VT_DISPATCH = 9,
203   VT_ERROR = 10,
204   VT_BOOL = 11,
205   VT_VARIANT = 12,
206   VT_UNKNOWN = 13,
207   VT_DECIMAL = 14,
208 
209   VT_I1 = 16,
210   VT_UI1 = 17,
211   VT_UI2 = 18,
212   VT_UI4 = 19,
213   VT_I8 = 20,
214   VT_UI8 = 21,
215   VT_INT = 22,
216   VT_UINT = 23,
217   VT_VOID = 24,
218   VT_HRESULT = 25,
219   VT_FILETIME = 64
220 };
221 
222 typedef unsigned short VARTYPE;
223 typedef WORD PROPVAR_PAD1;
224 typedef WORD PROPVAR_PAD2;
225 typedef WORD PROPVAR_PAD3;
226 
227 typedef struct tagPROPVARIANT
228 {
229   VARTYPE vt;
230   PROPVAR_PAD1 wReserved1;
231   PROPVAR_PAD2 wReserved2;
232   PROPVAR_PAD3 wReserved3;
233   union
234   {
235     CHAR cVal;
236     UCHAR bVal;
237     SHORT iVal;
238     USHORT uiVal;
239     LONG lVal;
240     ULONG ulVal;
241     INT intVal;
242     UINT uintVal;
243     LARGE_INTEGER hVal;
244     ULARGE_INTEGER uhVal;
245     VARIANT_BOOL boolVal;
246     SCODE scode;
247     FILETIME filetime;
248     BSTR bstrVal;
249   };
250 } PROPVARIANT;
251 
252 typedef PROPVARIANT tagVARIANT;
253 typedef tagVARIANT VARIANT;
254 typedef VARIANT VARIANTARG;
255 
256 EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
257 EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src);
258 
259 typedef struct tagSTATPROPSTG
260 {
261   LPOLESTR lpwstrName;
262   PROPID propid;
263   VARTYPE vt;
264 } STATPROPSTG;
265 
266 EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
267 EXTERN_C BSTR SysAllocStringLen(const OLECHAR *sz, UINT len);
268 EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
269 EXTERN_C void SysFreeString(BSTR bstr);
270 EXTERN_C UINT SysStringByteLen(BSTR bstr);
271 EXTERN_C UINT SysStringLen(BSTR bstr);
272 
273 EXTERN_C DWORD GetLastError();
274 EXTERN_C void SetLastError(DWORD dwCode);
275 EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
276 
277 EXTERN_C DWORD GetCurrentThreadId();
278 EXTERN_C DWORD GetCurrentProcessId();
279 
280 #define MAX_PATH 1024
281 
282 #define CP_ACP    0
283 #define CP_OEMCP  1
284 #define CP_UTF8   65001
285 
286 typedef enum tagSTREAM_SEEK
287 {
288   STREAM_SEEK_SET = 0,
289   STREAM_SEEK_CUR = 1,
290   STREAM_SEEK_END = 2
291 } STREAM_SEEK;
292 
293 
294 
295 typedef struct _SYSTEMTIME
296 {
297   WORD wYear;
298   WORD wMonth;
299   WORD wDayOfWeek;
300   WORD wDay;
301   WORD wHour;
302   WORD wMinute;
303   WORD wSecond;
304   WORD wMilliseconds;
305 } SYSTEMTIME;
306 
307 BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *fileTime, FILETIME *localFileTime);
308 BOOL WINAPI LocalFileTimeToFileTime(const FILETIME *localFileTime, FILETIME *fileTime);
309 BOOL WINAPI FileTimeToSystemTime(const FILETIME *fileTime, SYSTEMTIME *systemTime);
310 // VOID WINAPI GetSystemTimeAsFileTime(FILETIME *systemTimeAsFileTime);
311 
312 DWORD GetTickCount();
313 
314 
315 #define CREATE_NEW          1
316 #define CREATE_ALWAYS       2
317 #define OPEN_EXISTING       3
318 #define OPEN_ALWAYS         4
319 #define TRUNCATE_EXISTING   5
320 
321 
322 #endif // _WIN32
323 
324 #endif
325