2 * Copyright (c) 1997-1999
3 * Silicon Graphics Computer Systems, Inc.
11 * This material is provided "as is", with absolutely no warranty expressed
12 * or implied. Any use is at your own risk.
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.
21 #ifndef _STLP_INTERNAL_WINDOWS_H
22 #define _STLP_INTERNAL_WINDOWS_H
24 #if !defined (_STLP_PLATFORM)
25 # define _STLP_PLATFORM "Windows"
28 #if !defined (_STLP_BIG_ENDIAN) && !defined (_STLP_LITTLE_ENDIAN)
29 # if defined (_MIPSEB)
30 # define _STLP_BIG_ENDIAN 1
32 # if defined (__i386) || defined (_M_IX86) || defined (_M_ARM) || \
33 defined (__amd64__) || defined (_M_AMD64) || defined (__x86_64__) || \
35 # define _STLP_LITTLE_ENDIAN 1
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
42 # define _STLP_LITTLE_ENDIAN 1
45 #endif /* _STLP_BIG_ENDIAN */
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
57 # if !defined (WIN32_LEAN_AND_MEAN)
58 # define WIN32_LEAN_AND_MEAN
60 # if !defined (VC_EXTRALEAN)
63 /* Don't let windows.h define its min and max macros. */
64 # if !defined (NOMINMAX)
67 # if !defined (STRICT)
70 # if defined (_STLP_USE_MFC)
75 # if (_STLP_OUTERMOST_HEADER_ID == 0x100)
76 # undef _STLP_OUTERMOST_HEADER_ID
79 /* This section serves as a replacement for windows.h header. */
80 # if defined (__cplusplus)
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
91 # define _STLP_STDCALL _cdecl
93 # define _STLP_STDCALL __stdcall
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
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
);
110 # if defined (_WIN64)
111 _STLP_IMPORT_DECLSPEC
void* _STLP_STDCALL
_InterlockedExchangePointer(void* volatile *, void*);
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 ...
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);
121 /* start of eMbedded Visual C++ specific section */
122 # include <stl/config/_native_headers.h>
124 /* Don't let windef.h define its min and max macros. */
125 # if !defined (NOMINMAX)
128 # include <windef.h> /* needed for basic windows types */
130 /** in SDKs generated with PB5, windef.h somehow includes headers which then
132 # if (_WIN32_WCE >= 0x500)
133 # define _STLP_NATIVE_SETJMP_H_INCLUDED
136 # ifndef _WINBASE_ /* winbase.h already included? */
137 long WINAPI
InterlockedIncrement(long*);
138 long WINAPI
InterlockedDecrement(long*);
139 long WINAPI
InterlockedExchange(long*, long);
142 # ifndef __WINDOWS__ /* windows.h already included? */
145 # include <winbase.h> /* needed for inline versions of Interlocked* functions */
150 # define MessageBox MessageBoxW
151 int WINAPI
MessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
);
153 # define wvsprintf wvsprintfW
154 int WINAPI
wvsprintfW(LPWSTR
, LPCWSTR
, va_list ArgList
);
156 void WINAPI
ExitThread(DWORD dwExitCode
);
158 # if !defined (COREDLL)
159 # define _STLP_WCE_WINBASEAPI DECLSPEC_IMPORT
161 # define _STLP_WCE_WINBASEAPI
164 _STLP_WCE_WINBASEAPI
int WINAPI
165 MultiByteToWideChar(UINT CodePage
, DWORD dwFlags
, LPCSTR lpMultiByteStr
,
166 int cbMultiByte
, LPWSTR lpWideCharStr
, int cchWideChar
);
168 _STLP_WCE_WINBASEAPI UINT WINAPI
GetACP();
170 _STLP_WCE_WINBASEAPI BOOL WINAPI
TerminateProcess(HANDLE hProcess
, DWORD uExitCode
);
172 # define OutputDebugString OutputDebugStringW
173 void WINAPI
OutputDebugStringW(LPCWSTR
);
175 _STLP_WCE_WINBASEAPI
void WINAPI
Sleep(DWORD
);
177 # undef _STLP_WCE_WINBASEAPI
179 # endif /* !_MFC_VER */
181 # endif /* !__WINDOWS__ */
183 /* end of eMbedded Visual C++ specific section */
186 # if !defined (_STLP_WCE)
187 _STLP_IMPORT_DECLSPEC
void _STLP_STDCALL
OutputDebugStringA(const char* lpOutputString
);
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)
198 # if defined (__cplusplus)
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) && defined(__BUILDING_STLPORT)
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.
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
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
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
)));
228 return (void*)InterlockedExchange((long*)__a
, (long)__b
);
230 # if defined (_STLP_MSVC)
231 # pragma warning (pop)
236 # define STLPInterlockedExchangePointer _InterlockedExchangePointer
239 #endif /* _STLP_WINDOWS_H_INCLUDED */
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
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
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
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
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
269 # define _STLP_SIGNAL_RUNTIME_COMPATIBILITY building_for_at_least_windows98_but_library_built_for_windows95
272 # if defined (_STLP_WIN95_LIKE)
273 # define _STLP_CHECK_RUNTIME_COMPATIBILITY building_for_windows95_but_library_built_for_at_least_windows98
275 # define _STLP_CHECK_RUNTIME_COMPATIBILITY building_for_at_least_windows98_but_library_built_for_windows95
280 #if defined (__WIN16) || defined (WIN16) || defined (_WIN16)
287 #if defined(_STLP_WIN32)
288 # define _STLP_USE_WIN32_IO /* CreateFile/ReadFile/WriteFile */
292 #if defined(__MINGW32__) && !defined(_STLP_USE_STDIO_IO)
293 # define _STLP_USE_WIN32_IO /* CreateFile/ReadFile/WriteFile */
294 #endif /* __MINGW32__ */
297 # define _STLP_USE_UNIX_EMULATION_IO /* _open/_read/_write */
298 # define _STLP_LDOUBLE_80
301 #endif /* _STLP_INTERNAL_WINDOWS_H */