williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 1997-1999
|
williamr@2
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* Copyright (c) 1999
|
williamr@2
|
6 |
* Boris Fomitchev
|
williamr@2
|
7 |
*
|
williamr@2
|
8 |
* Copyright (c) 2003
|
williamr@2
|
9 |
* Francois Dumont
|
williamr@2
|
10 |
*
|
williamr@2
|
11 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
12 |
* or implied. Any use is at your own risk.
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
15 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
16 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
17 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
18 |
* modified is included with the above copyright notice.
|
williamr@2
|
19 |
*
|
williamr@2
|
20 |
*/
|
williamr@2
|
21 |
#ifndef _STLP_INTERNAL_WINDOWS_H
|
williamr@2
|
22 |
#define _STLP_INTERNAL_WINDOWS_H
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#if !defined (_STLP_PLATFORM)
|
williamr@2
|
25 |
# define _STLP_PLATFORM "Windows"
|
williamr@2
|
26 |
#endif
|
williamr@2
|
27 |
|
williamr@2
|
28 |
#if !defined (_STLP_BIG_ENDIAN) && !defined (_STLP_LITTLE_ENDIAN)
|
williamr@2
|
29 |
# if defined (_MIPSEB)
|
williamr@2
|
30 |
# define _STLP_BIG_ENDIAN 1
|
williamr@2
|
31 |
# endif
|
williamr@2
|
32 |
# if defined (__i386) || defined (_M_IX86) || defined (_M_ARM) || \
|
williamr@2
|
33 |
defined (__amd64__) || defined (_M_AMD64) || defined (__x86_64__) || \
|
williamr@2
|
34 |
defined (__alpha__)
|
williamr@2
|
35 |
# define _STLP_LITTLE_ENDIAN 1
|
williamr@2
|
36 |
# endif
|
williamr@2
|
37 |
# if defined (__ia64__)
|
williamr@2
|
38 |
/* itanium allows both settings (for instance via gcc -mbig-endian) - hence a seperate check is required */
|
williamr@2
|
39 |
# if defined (__BIG_ENDIAN__)
|
williamr@2
|
40 |
# define _STLP_BIG_ENDIAN 1
|
williamr@2
|
41 |
# else
|
williamr@2
|
42 |
# define _STLP_LITTLE_ENDIAN 1
|
williamr@2
|
43 |
# endif
|
williamr@2
|
44 |
# endif
|
williamr@2
|
45 |
#endif /* _STLP_BIG_ENDIAN */
|
williamr@2
|
46 |
|
williamr@2
|
47 |
#if !defined (_STLP_WINDOWS_H_INCLUDED)
|
williamr@2
|
48 |
# define _STLP_WINDOWS_H_INCLUDED
|
williamr@2
|
49 |
# if !(defined ( _STLP_MSVC ) || defined (__BORLANDC__) || defined (__ICL) || defined (__WATCOMC__) || \
|
williamr@2
|
50 |
defined (__MINGW32__) || defined (__DMC__))
|
williamr@2
|
51 |
# if defined (_STLP_USE_MFC)
|
williamr@2
|
52 |
# include <afx.h>
|
williamr@2
|
53 |
# else
|
williamr@2
|
54 |
# include <windows.h>
|
williamr@2
|
55 |
# endif
|
williamr@2
|
56 |
# else
|
williamr@2
|
57 |
/* This section serves as a replacement for windows.h header for Visual C++ */
|
williamr@2
|
58 |
# if defined (__cplusplus)
|
williamr@2
|
59 |
extern "C" {
|
williamr@2
|
60 |
# endif
|
williamr@2
|
61 |
# if (defined (_M_AMD64) || defined (_M_IA64) || (!defined (_STLP_WCE) && defined (_M_MRX000)) || defined (_M_ALPHA) || \
|
williamr@2
|
62 |
(defined (_M_PPC) && (_STLP_MSVC_LIB >= 1000))) && !defined (RC_INVOKED)
|
williamr@2
|
63 |
# define InterlockedIncrement _InterlockedIncrement
|
williamr@2
|
64 |
# define InterlockedDecrement _InterlockedDecrement
|
williamr@2
|
65 |
# define InterlockedExchange _InterlockedExchange
|
williamr@2
|
66 |
/* Here we use a different macro name than the InterlockedExchangePointer SDK function
|
williamr@2
|
67 |
* to avoid macro definition conflict as the SDK might already define InterlockedExchangePointer
|
williamr@2
|
68 |
* as a macro.
|
williamr@2
|
69 |
*/
|
williamr@2
|
70 |
# define STLPInterlockedExchangePointer _InterlockedExchangePointer
|
williamr@2
|
71 |
# define _STLP_STDCALL
|
williamr@2
|
72 |
# else
|
williamr@2
|
73 |
# if defined (_MAC)
|
williamr@2
|
74 |
# define _STLP_STDCALL _cdecl
|
williamr@2
|
75 |
# else
|
williamr@2
|
76 |
# define _STLP_STDCALL __stdcall
|
williamr@2
|
77 |
# endif
|
williamr@2
|
78 |
# endif
|
williamr@2
|
79 |
|
williamr@2
|
80 |
# if defined (_STLP_NEW_PLATFORM_SDK)
|
williamr@2
|
81 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedIncrement(long volatile *);
|
williamr@2
|
82 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedDecrement(long volatile *);
|
williamr@2
|
83 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedExchange(long volatile *, long);
|
williamr@2
|
84 |
# if defined (STLPInterlockedExchangePointer)
|
williamr@2
|
85 |
_STLP_IMPORT_DECLSPEC void* _STLP_STDCALL STLPInterlockedExchangePointer(void* volatile *, void*);
|
williamr@2
|
86 |
# endif
|
williamr@2
|
87 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedExchangeAdd(long volatile *, long);
|
williamr@2
|
88 |
# elif defined (_STLP_WCE)
|
williamr@2
|
89 |
|
williamr@2
|
90 |
/* start of eMbedded Visual C++ specific section */
|
williamr@2
|
91 |
# include <windef.h> /* needed for basic windows types */
|
williamr@2
|
92 |
|
williamr@2
|
93 |
/** in SDKs generated with PB5, windef.h somehow includes headers which then
|
williamr@2
|
94 |
define setjmp. */
|
williamr@2
|
95 |
# if (_WIN32_WCE >= 0x500)
|
williamr@2
|
96 |
# define _STLP_NATIVE_SETJMP_H_INCLUDED
|
williamr@2
|
97 |
# endif
|
williamr@2
|
98 |
|
williamr@2
|
99 |
# ifndef _WINBASE_ /* winbase.h already included? */
|
williamr@2
|
100 |
long WINAPI InterlockedIncrement(long*);
|
williamr@2
|
101 |
long WINAPI InterlockedDecrement(long*);
|
williamr@2
|
102 |
long WINAPI InterlockedExchange(long*, long);
|
williamr@2
|
103 |
# endif
|
williamr@2
|
104 |
|
williamr@2
|
105 |
# ifndef __WINDOWS__ /* windows.h already included? */
|
williamr@2
|
106 |
|
williamr@2
|
107 |
# if defined (x86)
|
williamr@2
|
108 |
# include <winbase.h> /* needed for inline versions of Interlocked* functions */
|
williamr@2
|
109 |
# endif
|
williamr@2
|
110 |
|
williamr@2
|
111 |
# ifndef _MFC_VER
|
williamr@2
|
112 |
|
williamr@2
|
113 |
# define MessageBox MessageBoxW
|
williamr@2
|
114 |
int WINAPI MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
|
williamr@2
|
115 |
|
williamr@2
|
116 |
# define wvsprintf wvsprintfW
|
williamr@2
|
117 |
int WINAPI wvsprintfW(LPWSTR, LPCWSTR, va_list ArgList);
|
williamr@2
|
118 |
|
williamr@2
|
119 |
void WINAPI ExitThread(DWORD dwExitCode);
|
williamr@2
|
120 |
|
williamr@2
|
121 |
# if !defined (COREDLL)
|
williamr@2
|
122 |
# define _STLP_WCE_WINBASEAPI DECLSPEC_IMPORT
|
williamr@2
|
123 |
# else
|
williamr@2
|
124 |
# define _STLP_WCE_WINBASEAPI
|
williamr@2
|
125 |
# endif
|
williamr@2
|
126 |
|
williamr@2
|
127 |
_STLP_WCE_WINBASEAPI int WINAPI
|
williamr@2
|
128 |
MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
|
williamr@2
|
129 |
int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
|
williamr@2
|
130 |
|
williamr@2
|
131 |
_STLP_WCE_WINBASEAPI UINT WINAPI GetACP();
|
williamr@2
|
132 |
|
williamr@2
|
133 |
_STLP_WCE_WINBASEAPI BOOL WINAPI TerminateProcess(HANDLE hProcess, DWORD uExitCode);
|
williamr@2
|
134 |
|
williamr@2
|
135 |
# define OutputDebugString OutputDebugStringW
|
williamr@2
|
136 |
void WINAPI OutputDebugStringW(LPCWSTR);
|
williamr@2
|
137 |
|
williamr@2
|
138 |
_STLP_WCE_WINBASEAPI void WINAPI Sleep(DWORD);
|
williamr@2
|
139 |
|
williamr@2
|
140 |
# undef _STLP_WCE_WINBASEAPI
|
williamr@2
|
141 |
|
williamr@2
|
142 |
# endif /* !_MFC_VER */
|
williamr@2
|
143 |
|
williamr@2
|
144 |
# endif /* !__WINDOWS__ */
|
williamr@2
|
145 |
|
williamr@2
|
146 |
/* end of eMbedded Visual C++ specific section */
|
williamr@2
|
147 |
|
williamr@2
|
148 |
# else
|
williamr@2
|
149 |
/* boris : for the latest SDK, you may actually need the other version of the declaration (above)
|
williamr@2
|
150 |
* even for earlier VC++ versions. There is no way to tell SDK versions apart, sorry ...
|
williamr@2
|
151 |
*/
|
williamr@2
|
152 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedIncrement(long*);
|
williamr@2
|
153 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedDecrement(long*);
|
williamr@2
|
154 |
_STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedExchange(long*, long);
|
williamr@2
|
155 |
# endif
|
williamr@2
|
156 |
|
williamr@2
|
157 |
# if !defined (STLPInterlockedExchangePointer)
|
williamr@2
|
158 |
/* This API function do not exist in the old platform SDK and is equivalent to
|
williamr@2
|
159 |
* InterlockedExchange on 32 bits platform:
|
williamr@2
|
160 |
*/
|
williamr@2
|
161 |
# if defined (__cplusplus)
|
williamr@2
|
162 |
/* We do not define this function if we are not in a C++ translation unit just
|
williamr@2
|
163 |
* because of the inline portability issue it would introduce. We will have to
|
williamr@2
|
164 |
* fix it the day we need this function for a C translation unit.
|
williamr@2
|
165 |
*/
|
williamr@2
|
166 |
inline
|
williamr@2
|
167 |
void* _STLP_CALL STLPInterlockedExchangePointer(void* volatile* __a, void* __b) {
|
williamr@2
|
168 |
# if defined (_STLP_MSVC)
|
williamr@2
|
169 |
/* Here MSVC produces warning if 64 bits portability issue is activated.
|
williamr@2
|
170 |
* MSVC do not see that _STLP_ATOMIC_EXCHANGE_PTR is a macro which content
|
williamr@2
|
171 |
* is based on the platform, Win32 or Win64
|
williamr@2
|
172 |
*/
|
williamr@2
|
173 |
# pragma warning (push)
|
williamr@2
|
174 |
# pragma warning (disable : 4311) // pointer truncation from void* to long
|
williamr@2
|
175 |
# pragma warning (disable : 4312) // conversion from long to void* of greater size
|
williamr@2
|
176 |
# endif
|
williamr@2
|
177 |
# if !defined (_STLP_NO_NEW_STYLE_CASTS)
|
williamr@2
|
178 |
return reinterpret_cast<void*>(InterlockedExchange(reinterpret_cast<long*>(const_cast<void**>(__a)),
|
williamr@2
|
179 |
reinterpret_cast<long>(__b)));
|
williamr@2
|
180 |
# else
|
williamr@2
|
181 |
return (void*)InterlockedExchange((long*)__a, (long)__b);
|
williamr@2
|
182 |
# endif
|
williamr@2
|
183 |
# if defined (_STLP_MSVC)
|
williamr@2
|
184 |
# pragma warning (pop)
|
williamr@2
|
185 |
# endif
|
williamr@2
|
186 |
}
|
williamr@2
|
187 |
# endif
|
williamr@2
|
188 |
# endif
|
williamr@2
|
189 |
|
williamr@2
|
190 |
# if !defined (_STLP_WCE)
|
williamr@2
|
191 |
_STLP_IMPORT_DECLSPEC void _STLP_STDCALL Sleep(unsigned long);
|
williamr@2
|
192 |
_STLP_IMPORT_DECLSPEC void _STLP_STDCALL OutputDebugStringA(const char* lpOutputString);
|
williamr@2
|
193 |
# endif
|
williamr@2
|
194 |
|
williamr@2
|
195 |
# if defined (InterlockedIncrement)
|
williamr@2
|
196 |
# pragma intrinsic(_InterlockedIncrement)
|
williamr@2
|
197 |
# pragma intrinsic(_InterlockedDecrement)
|
williamr@2
|
198 |
# pragma intrinsic(_InterlockedExchange)
|
williamr@2
|
199 |
# pragma intrinsic(_InterlockedExchangePointer)
|
williamr@2
|
200 |
# endif
|
williamr@2
|
201 |
# if defined (__cplusplus)
|
williamr@2
|
202 |
} /* extern "C" */
|
williamr@2
|
203 |
# endif
|
williamr@2
|
204 |
|
williamr@2
|
205 |
# endif /* STL_MSVC __BORLANDC__ __ICL __WATCOMC__ __MINGW32__ __DMC__*/
|
williamr@2
|
206 |
|
williamr@2
|
207 |
#endif /* _STLP_WINDOWS_H_INCLUDED */
|
williamr@2
|
208 |
|
williamr@2
|
209 |
#endif /* _STLP_INTERNAL_WINDOWS_H */
|