• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // MyWindows.h
2 
3 #ifndef __MY_WINDOWS_H
4 #define __MY_WINDOWS_H
5 
6 #ifdef _WIN32
7 
8 #include <windows.h>
9 
10 #ifdef UNDER_CE
11   #undef VARIANT_TRUE
12   #define VARIANT_TRUE ((VARIANT_BOOL)-1)
13 #endif
14 
15 #else // _WIN32
16 
17 #include <stddef.h> // for wchar_t
18 #include <string.h>
19 // #include <stdint.h> // for uintptr_t
20 
21 #include "MyGuidDef.h"
22 
23 // WINAPI is __stdcall in Windows-MSVC in windef.h
24 #define WINAPI
25 #define EXTERN_C MY_EXTERN_C
26 
27 typedef char CHAR;
28 typedef unsigned char UCHAR;
29 
30 #undef BYTE
31 typedef unsigned char BYTE;
32 
33 typedef short SHORT;
34 typedef unsigned short USHORT;
35 
36 #undef WORD
37 typedef unsigned short WORD;
38 typedef short VARIANT_BOOL;
39 
40 #define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff))
41 #define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16))
42 
43 // MS uses long for BOOL, but long is 32-bit in MS. So we use int.
44 // typedef long BOOL;
45 typedef int BOOL;
46 
47 #ifndef FALSE
48   #define FALSE 0
49   #define TRUE 1
50 #endif
51 
52 // typedef size_t ULONG_PTR;
53 // typedef size_t DWORD_PTR;
54 // typedef uintptr_t UINT_PTR;
55 // typedef ptrdiff_t UINT_PTR;
56 
57 typedef Int64 LONGLONG;
58 typedef UInt64 ULONGLONG;
59 
60 typedef struct _LARGE_INTEGER { LONGLONG QuadPart; } LARGE_INTEGER;
61 typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart; } ULARGE_INTEGER;
62 
63 typedef const CHAR *LPCSTR;
64 typedef CHAR TCHAR;
65 typedef const TCHAR *LPCTSTR;
66 typedef wchar_t WCHAR;
67 typedef WCHAR OLECHAR;
68 typedef const WCHAR *LPCWSTR;
69 typedef OLECHAR *BSTR;
70 typedef const OLECHAR *LPCOLESTR;
71 typedef OLECHAR *LPOLESTR;
72 
73 typedef struct _FILETIME
74 {
75   DWORD dwLowDateTime;
76   DWORD dwHighDateTime;
77 } FILETIME;
78 
79 #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
80 #define FAILED(hr)    ((HRESULT)(hr) < 0)
81 typedef ULONG PROPID;
82 typedef LONG SCODE;
83 
84 
85 #define S_OK    ((HRESULT)0x00000000L)
86 #define S_FALSE ((HRESULT)0x00000001L)
87 #define E_NOTIMPL     ((HRESULT)0x80004001L)
88 #define E_NOINTERFACE ((HRESULT)0x80004002L)
89 #define E_ABORT       ((HRESULT)0x80004004L)
90 #define E_FAIL        ((HRESULT)0x80004005L)
91 #define STG_E_INVALIDFUNCTION     ((HRESULT)0x80030001L)
92 #define CLASS_E_CLASSNOTAVAILABLE ((HRESULT)0x80040111L)
93 
94 
95 #ifdef _MSC_VER
96 #define STDMETHODCALLTYPE __stdcall
97 #define STDAPICALLTYPE    __stdcall
98 #else
99 // do we need __export here?
100 #define STDMETHODCALLTYPE
101 #define STDAPICALLTYPE
102 #endif
103 
104 #define STDAPI  EXTERN_C HRESULT STDAPICALLTYPE
105 
106 #define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f
107 #define STDMETHOD(f) STDMETHOD_(HRESULT, f)
108 #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
109 #define STDMETHODIMP STDMETHODIMP_(HRESULT)
110 
111 #define PURE = 0
112 
113 #define MIDL_INTERFACE(x) struct
114 
115 #ifdef __cplusplus
116 
117 DEFINE_GUID(IID_IUnknown,
118 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
119 struct IUnknown
120 {
121   STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
122   STDMETHOD_(ULONG, AddRef)() PURE;
123   STDMETHOD_(ULONG, Release)() PURE;
~IUnknownIUnknown124   virtual ~IUnknown() {}
125   // We use virtual ~IUnknown() here for binary compatibility with 7z.so from p7zip
126 };
127 
128 typedef IUnknown *LPUNKNOWN;
129 
130 #endif
131 
132 #define VARIANT_TRUE ((VARIANT_BOOL)-1)
133 #define VARIANT_FALSE ((VARIANT_BOOL)0)
134 
135 enum VARENUM
136 {
137   VT_EMPTY = 0,
138   VT_NULL = 1,
139   VT_I2 = 2,
140   VT_I4 = 3,
141   VT_R4 = 4,
142   VT_R8 = 5,
143   VT_CY = 6,
144   VT_DATE = 7,
145   VT_BSTR = 8,
146   VT_DISPATCH = 9,
147   VT_ERROR = 10,
148   VT_BOOL = 11,
149   VT_VARIANT = 12,
150   VT_UNKNOWN = 13,
151   VT_DECIMAL = 14,
152 
153   VT_I1 = 16,
154   VT_UI1 = 17,
155   VT_UI2 = 18,
156   VT_UI4 = 19,
157   VT_I8 = 20,
158   VT_UI8 = 21,
159   VT_INT = 22,
160   VT_UINT = 23,
161   VT_VOID = 24,
162   VT_HRESULT = 25,
163   VT_FILETIME = 64
164 };
165 
166 typedef unsigned short VARTYPE;
167 typedef WORD PROPVAR_PAD1;
168 typedef WORD PROPVAR_PAD2;
169 typedef WORD PROPVAR_PAD3;
170 
171 typedef struct tagPROPVARIANT
172 {
173   VARTYPE vt;
174   PROPVAR_PAD1 wReserved1;
175   PROPVAR_PAD2 wReserved2;
176   PROPVAR_PAD3 wReserved3;
177   union
178   {
179     CHAR cVal;
180     UCHAR bVal;
181     SHORT iVal;
182     USHORT uiVal;
183     LONG lVal;
184     ULONG ulVal;
185     INT intVal;
186     UINT uintVal;
187     LARGE_INTEGER hVal;
188     ULARGE_INTEGER uhVal;
189     VARIANT_BOOL boolVal;
190     SCODE scode;
191     FILETIME filetime;
192     BSTR bstrVal;
193   };
194 } PROPVARIANT;
195 
196 typedef PROPVARIANT tagVARIANT;
197 typedef tagVARIANT VARIANT;
198 typedef VARIANT VARIANTARG;
199 
200 MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
201 MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, const VARIANTARG *src);
202 
203 typedef struct tagSTATPROPSTG
204 {
205   LPOLESTR lpwstrName;
206   PROPID propid;
207   VARTYPE vt;
208 } STATPROPSTG;
209 
210 MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
211 MY_EXTERN_C BSTR SysAllocStringLen(const OLECHAR *sz, UINT len);
212 MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
213 MY_EXTERN_C void SysFreeString(BSTR bstr);
214 MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
215 MY_EXTERN_C UINT SysStringLen(BSTR bstr);
216 
217 MY_EXTERN_C DWORD GetLastError();
218 MY_EXTERN_C void SetLastError(DWORD dwCode);
219 MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
220 
221 MY_EXTERN_C DWORD GetCurrentThreadId();
222 MY_EXTERN_C DWORD GetCurrentProcessId();
223 
224 #define MAX_PATH 1024
225 
226 #define CP_ACP    0
227 #define CP_OEMCP  1
228 #define CP_UTF8   65001
229 
230 typedef enum tagSTREAM_SEEK
231 {
232   STREAM_SEEK_SET = 0,
233   STREAM_SEEK_CUR = 1,
234   STREAM_SEEK_END = 2
235 } STREAM_SEEK;
236 
237 
238 
239 typedef struct _SYSTEMTIME
240 {
241   WORD wYear;
242   WORD wMonth;
243   WORD wDayOfWeek;
244   WORD wDay;
245   WORD wHour;
246   WORD wMinute;
247   WORD wSecond;
248   WORD wMilliseconds;
249 } SYSTEMTIME;
250 
251 BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *fileTime, FILETIME *localFileTime);
252 BOOL WINAPI LocalFileTimeToFileTime(const FILETIME *localFileTime, FILETIME *fileTime);
253 BOOL WINAPI FileTimeToSystemTime(const FILETIME *fileTime, SYSTEMTIME *systemTime);
254 // VOID WINAPI GetSystemTimeAsFileTime(FILETIME *systemTimeAsFileTime);
255 
256 DWORD GetTickCount();
257 
258 
259 #define CREATE_NEW          1
260 #define CREATE_ALWAYS       2
261 #define OPEN_EXISTING       3
262 #define OPEN_ALWAYS         4
263 #define TRUNCATE_EXISTING   5
264 
265 
266 #endif // _WIN32
267 
268 #endif
269