1 /*
2 * Copyright (c) 1997-1999
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Copyright (c) 1999
6 * Boris Fomitchev
7 *
8 * Copyright (c) 2003
9 * Francois Dumont
10 *
11 * This material is provided "as is", with absolutely no warranty expressed
12 * or implied. Any use is at your own risk.
13 *
14 * Permission to use or copy this software for any purpose is hereby granted
15 * without fee, provided the above notices are retained on all copies.
16 * Permission to modify the code and to distribute modified code is granted,
17 * provided the above notices are retained, and a notice that the code was
18 * modified is included with the above copyright notice.
19 *
20 */
21 #ifndef _STLP_INTERNAL_WINDOWS_H
22 #define _STLP_INTERNAL_WINDOWS_H
23
24 #if !defined (_STLP_PLATFORM)
25 # define _STLP_PLATFORM "Windows"
26 #endif
27
28 #if !defined (_STLP_BIG_ENDIAN) && !defined (_STLP_LITTLE_ENDIAN)
29 # if defined (_MIPSEB)
30 # define _STLP_BIG_ENDIAN 1
31 # endif
32 # if defined (__i386) || defined (_M_IX86) || defined (_M_ARM) || \
33 defined (__amd64__) || defined (_M_AMD64) || defined (__x86_64__) || \
34 defined (__alpha__)
35 # define _STLP_LITTLE_ENDIAN 1
36 # endif
37 # if defined (__ia64__)
38 /* itanium allows both settings (for instance via gcc -mbig-endian) - hence a seperate check is required */
39 # if defined (__BIG_ENDIAN__)
40 # define _STLP_BIG_ENDIAN 1
41 # else
42 # define _STLP_LITTLE_ENDIAN 1
43 # endif
44 # endif
45 #endif /* _STLP_BIG_ENDIAN */
46
47 #if !defined (_STLP_WINDOWS_H_INCLUDED)
48 # define _STLP_WINDOWS_H_INCLUDED
49 # if defined (__BUILDING_STLPORT)
50 # include <stl/config/_native_headers.h>
51 /* Here we define _STLP_OUTERMOST_HEADER_ID to avoid indirect inclusion
52 * of STLport stuffs from C/C++ Standard headers exposed by STLport
53 * as configuration is not yet completed. */
54 # if !defined (_STLP_OUTERMOST_HEADER_ID)
55 # define _STLP_OUTERMOST_HEADER_ID 0x100
56 # endif
57 # if !defined (WIN32_LEAN_AND_MEAN)
58 # define WIN32_LEAN_AND_MEAN
59 # endif
60 # if !defined (VC_EXTRALEAN)
61 # define VC_EXTRALEAN
62 # endif
63 /* Don't let windows.h define its min and max macros. */
64 # if !defined (NOMINMAX)
65 # define NOMINMAX
66 # endif
67 # if !defined (STRICT)
68 # define STRICT
69 # endif
70 # if defined (_STLP_USE_MFC)
71 # include <afx.h>
72 # else
73 # include <windows.h>
74 # endif
75 # if (_STLP_OUTERMOST_HEADER_ID == 0x100)
76 # undef _STLP_OUTERMOST_HEADER_ID
77 # endif
78 # else
79 /* This section serves as a replacement for windows.h header. */
80 # if defined (__cplusplus)
81 extern "C" {
82 # endif
83 # if (defined (_M_AMD64) || defined (_M_IA64) || (!defined (_STLP_WCE) && defined (_M_MRX000)) || defined (_M_ALPHA) || \
84 (defined (_M_PPC) && (_STLP_MSVC_LIB >= 1000))) && !defined (RC_INVOKED)
85 # define InterlockedIncrement _InterlockedIncrement
86 # define InterlockedDecrement _InterlockedDecrement
87 # define InterlockedExchange _InterlockedExchange
88 # define _STLP_STDCALL
89 # else
90 # if defined (_MAC)
91 # define _STLP_STDCALL _cdecl
92 # else
93 # define _STLP_STDCALL __stdcall
94 # endif
95 # endif
96
97 # if defined (_STLP_NEW_PLATFORM_SDK) && !defined(_WDMDDK_)
98 /* Define WIN32_NO_STATUS to prevent status codes redefinitions */
99 # if !defined(WIN32_NO_STATUS)
100 # define WIN32_NO_STATUS
101 # endif
102 # include <windef.h>
103
104 #ifndef InterlockedIncrement
105 _STLP_IMPORT_DECLSPEC LONG _STLP_STDCALL InterlockedIncrement(IN OUT LONG volatile *);
106 _STLP_IMPORT_DECLSPEC LONG _STLP_STDCALL InterlockedDecrement(IN OUT LONG volatile *);
107 _STLP_IMPORT_DECLSPEC LONG _STLP_STDCALL InterlockedExchange(IN OUT LONG volatile *, LONG);
108 _STLP_IMPORT_DECLSPEC void _STLP_STDCALL Sleep(DWORD);
109 #endif
110 # if defined (_WIN64)
111 _STLP_IMPORT_DECLSPEC void* _STLP_STDCALL _InterlockedExchangePointer(void* volatile *, void*);
112 # endif
113 # elif !defined (_STLP_WCE)
114 /* boris : for the latest SDK, you may actually need the other version of the declaration (above)
115 * even for earlier VC++ versions. There is no way to tell SDK versions apart, sorry ...
116 */
117 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedIncrement(long volatile *);
118 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedDecrement(long volatile *);
119 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedExchange(long volatile *, long);
120 # else
121 /* start of eMbedded Visual C++ specific section */
122 # include <stl/config/_native_headers.h>
123
124 /* Don't let windef.h define its min and max macros. */
125 # if !defined (NOMINMAX)
126 # define NOMINMAX
127 # endif
128 # include <windef.h> /* needed for basic windows types */
129
130 /** in SDKs generated with PB5, windef.h somehow includes headers which then
131 define setjmp. */
132 # if (_WIN32_WCE >= 0x500)
133 # define _STLP_NATIVE_SETJMP_H_INCLUDED
134 # endif
135
136 # ifndef _WINBASE_ /* winbase.h already included? */
137 long WINAPI InterlockedIncrement(long*);
138 long WINAPI InterlockedDecrement(long*);
139 long WINAPI InterlockedExchange(long*, long);
140 # endif
141
142 # ifndef __WINDOWS__ /* windows.h already included? */
143
144 # if defined (x86)
145 # include <winbase.h> /* needed for inline versions of Interlocked* functions */
146 # endif
147
148 # ifndef _MFC_VER
149
150 # define MessageBox MessageBoxW
151 int WINAPI MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
152
153 # define wvsprintf wvsprintfW
154 int WINAPI wvsprintfW(LPWSTR, LPCWSTR, va_list ArgList);
155
156 void WINAPI ExitThread(DWORD dwExitCode);
157
158 # if !defined (COREDLL)
159 # define _STLP_WCE_WINBASEAPI DECLSPEC_IMPORT
160 # else
161 # define _STLP_WCE_WINBASEAPI
162 # endif
163
164 _STLP_WCE_WINBASEAPI int WINAPI
165 MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
166 int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
167
168 _STLP_WCE_WINBASEAPI UINT WINAPI GetACP();
169
170 _STLP_WCE_WINBASEAPI BOOL WINAPI TerminateProcess(HANDLE hProcess, DWORD uExitCode);
171
172 # define OutputDebugString OutputDebugStringW
173 void WINAPI OutputDebugStringW(LPCWSTR);
174
175 _STLP_WCE_WINBASEAPI void WINAPI Sleep(DWORD);
176
177 # undef _STLP_WCE_WINBASEAPI
178
179 # endif /* !_MFC_VER */
180
181 # endif /* !__WINDOWS__ */
182
183 /* end of eMbedded Visual C++ specific section */
184 # endif
185
186 # if !defined (_STLP_WCE)
187 _STLP_IMPORT_DECLSPEC void _STLP_STDCALL OutputDebugStringA(const char* lpOutputString);
188 # endif
189
190 # if defined (InterlockedIncrement) && defined(_MSC_VER)
191 # pragma intrinsic(_InterlockedIncrement)
192 # pragma intrinsic(_InterlockedDecrement)
193 # pragma intrinsic(_InterlockedExchange)
194 # if defined (_WIN64)
195 # pragma intrinsic(_InterlockedExchangePointer)
196 # endif
197 # endif
198 # if defined (__cplusplus)
199 } /* extern "C" */
200 # endif
201
202 # endif
203
204 /* Here we use a macro different than the InterlockedExchangePointer SDK one
205 * to avoid macro definition conflict. */
206 # if !defined (_WIN64)
207 /* Under 32 bits platform we rely on a simple InterlockedExchange call. */
208 # if defined (__cplusplus)
209 /* We do not define this function if we are not in a C++ translation unit just
210 * because of the 'inline' keyword portability issue it would introduce. We will
211 * have to fix it the day we need this function for a C translation unit.
212 */
213 inline
STLPInterlockedExchangePointer(void * volatile * __a,void * __b)214 void* _STLP_CALL STLPInterlockedExchangePointer(void* volatile* __a, void* __b) {
215 # if defined (_STLP_MSVC)
216 /* Here MSVC produces warning if 64 bits portability issue is activated.
217 * MSVC do not see that _STLP_ATOMIC_EXCHANGE_PTR is a macro which content
218 * is based on the platform, Win32 or Win64
219 */
220 # pragma warning (push)
221 # pragma warning (disable : 4311) // pointer truncation from void* to long
222 # pragma warning (disable : 4312) // conversion from long to void* of greater size
223 # endif
224 # if !defined (_STLP_NO_NEW_STYLE_CASTS)
225 return reinterpret_cast<void*>(InterlockedExchange(reinterpret_cast<long*>(const_cast<void**>(__a)),
226 reinterpret_cast<long>(__b)));
227 # else
228 return (void*)InterlockedExchange((long*)__a, (long)__b);
229 # endif
230 # if defined (_STLP_MSVC)
231 # pragma warning (pop)
232 # endif
233 }
234 # endif
235 # else
236 # define STLPInterlockedExchangePointer _InterlockedExchangePointer
237 # endif
238
239 #endif /* _STLP_WINDOWS_H_INCLUDED */
240
241 /* _STLP_WIN95_LIKE signal the Windows 95 OS or assimilated Windows OS version that
242 * has Interlockeded[Increment, Decrement] Win32 API functions not returning modified
243 * value.
244 */
245 #if (defined (WINVER) && (WINVER < 0x0410) && (!defined (_WIN32_WINNT) || (_WIN32_WINNT < 0x400))) || \
246 (!defined (WINVER) && (defined (_WIN32_WINDOWS) && (_WIN32_WINDOWS < 0x0410) || \
247 (defined (_WIN32_WINNT) && (_WIN32_WINNT < 0x400))))
248 # define _STLP_WIN95_LIKE
249 #endif
250
251 /* Between Windows 95 (0x400) and later Windows OSes an API enhancement forces us
252 * to change _Refcount_Base internal struct. As _Refcount_base member methods might
253 * be partially inlined we need to check that STLport build/use are coherent. To do
254 * so we try to generate a link time error thanks to the following macro.
255 * This additional check is limited to old compilers that might still be used with
256 * Windows 95. */
257 #if (defined (_DEBUG) || defined (_STLP_DEBUG)) && \
258 (defined (_STLP_MSVC) && (_STLP_MSVC < 1310) || \
259 defined (__GNUC__) && (__GNUC__ < 3))
260 /* We invert symbol names based on macro detection, when building for Windows
261 * 95 we expose a
262 * building_for_windows95_or_previous_but_library_built_for_windows98_or_later
263 * function in order to have a more obvious link error message signaling how
264 * the lib has been built and how it is used. */
265 # if defined (__BUILDING_STLPORT)
266 # if defined (_STLP_WIN95_LIKE)
267 # define _STLP_SIGNAL_RUNTIME_COMPATIBILITY building_for_windows95_but_library_built_for_at_least_windows98
268 # else
269 # define _STLP_SIGNAL_RUNTIME_COMPATIBILITY building_for_at_least_windows98_but_library_built_for_windows95
270 # endif
271 # else
272 # if defined (_STLP_WIN95_LIKE)
273 # define _STLP_CHECK_RUNTIME_COMPATIBILITY building_for_windows95_but_library_built_for_at_least_windows98
274 # else
275 # define _STLP_CHECK_RUNTIME_COMPATIBILITY building_for_at_least_windows98_but_library_built_for_windows95
276 # endif
277 # endif
278 #endif
279
280 #if defined (__WIN16) || defined (WIN16) || defined (_WIN16)
281 # define _STLP_WIN16
282 #else
283 # define _STLP_WIN32
284 #endif
285
286 #if 0
287 #if defined(_STLP_WIN32)
288 # define _STLP_USE_WIN32_IO /* CreateFile/ReadFile/WriteFile */
289 #endif
290 #endif
291
292 #if defined(__MINGW32__) && !defined(_STLP_USE_STDIO_IO)
293 # define _STLP_USE_WIN32_IO /* CreateFile/ReadFile/WriteFile */
294 #endif /* __MINGW32__ */
295
296 #ifdef _STLP_WIN16
297 # define _STLP_USE_UNIX_EMULATION_IO /* _open/_read/_write */
298 # define _STLP_LDOUBLE_80
299 #endif
300
301 #endif /* _STLP_INTERNAL_WINDOWS_H */
302