_windows.h 10 KB

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