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