SDL_windows.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. // This is an include file for windows.h with the SDL build settings
  19. #ifndef _INCLUDED_WINDOWS_H
  20. #define _INCLUDED_WINDOWS_H
  21. #ifdef SDL_PLATFORM_WIN32
  22. #ifndef WIN32_LEAN_AND_MEAN
  23. #define WIN32_LEAN_AND_MEAN 1
  24. #endif
  25. #ifndef STRICT
  26. #define STRICT 1
  27. #endif
  28. #ifndef UNICODE
  29. #define UNICODE 1
  30. #endif
  31. #undef WINVER
  32. #undef _WIN32_WINNT
  33. #if defined(SDL_VIDEO_RENDER_D3D12) || defined(HAVE_DXGI1_6_H)
  34. #define _WIN32_WINNT 0xA00 // For D3D12, 0xA00 is required
  35. #elif defined(HAVE_SHELLSCALINGAPI_H)
  36. #define _WIN32_WINNT 0x603 // For DPI support
  37. #else
  38. #define _WIN32_WINNT 0x501 // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input
  39. #endif
  40. #define WINVER _WIN32_WINNT
  41. #elif defined(SDL_PLATFORM_WINGDK)
  42. #ifndef WIN32_LEAN_AND_MEAN
  43. #define WIN32_LEAN_AND_MEAN 1
  44. #endif
  45. #ifndef STRICT
  46. #define STRICT 1
  47. #endif
  48. #ifndef UNICODE
  49. #define UNICODE 1
  50. #endif
  51. #undef WINVER
  52. #undef _WIN32_WINNT
  53. #define _WIN32_WINNT 0xA00
  54. #define WINVER _WIN32_WINNT
  55. #elif defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
  56. #ifndef WIN32_LEAN_AND_MEAN
  57. #define WIN32_LEAN_AND_MEAN 1
  58. #endif
  59. #ifndef STRICT
  60. #define STRICT 1
  61. #endif
  62. #ifndef UNICODE
  63. #define UNICODE 1
  64. #endif
  65. #undef WINVER
  66. #undef _WIN32_WINNT
  67. #define _WIN32_WINNT 0xA00
  68. #define WINVER _WIN32_WINNT
  69. #endif
  70. // See https://github.com/libsdl-org/SDL/pull/7607
  71. // force_align_arg_pointer attribute requires gcc >= 4.2.x.
  72. #if defined(__clang__)
  73. #define HAVE_FORCE_ALIGN_ARG_POINTER
  74. #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
  75. #define HAVE_FORCE_ALIGN_ARG_POINTER
  76. #endif
  77. #if defined(__GNUC__) && defined(__i386__) && defined(HAVE_FORCE_ALIGN_ARG_POINTER)
  78. #define MINGW32_FORCEALIGN __attribute__((force_align_arg_pointer))
  79. #else
  80. #define MINGW32_FORCEALIGN
  81. #endif
  82. #include <windows.h>
  83. #include <basetyps.h> // for REFIID with broken mingw.org headers
  84. #include <mmreg.h>
  85. // Routines to convert from UTF8 to native Windows text
  86. #define WIN_StringToUTF8W(S) SDL_iconv_string("UTF-8", "UTF-16LE", (const char *)(S), (SDL_wcslen(S) + 1) * sizeof(WCHAR))
  87. #define WIN_UTF8ToStringW(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (const char *)(S), SDL_strlen(S) + 1)
  88. // !!! FIXME: UTF8ToString() can just be a SDL_strdup() here.
  89. #define WIN_StringToUTF8A(S) SDL_iconv_string("UTF-8", "ASCII", (const char *)(S), (SDL_strlen(S) + 1))
  90. #define WIN_UTF8ToStringA(S) SDL_iconv_string("ASCII", "UTF-8", (const char *)(S), SDL_strlen(S) + 1)
  91. #if UNICODE
  92. #define WIN_StringToUTF8 WIN_StringToUTF8W
  93. #define WIN_UTF8ToString WIN_UTF8ToStringW
  94. #define SDL_tcslen SDL_wcslen
  95. #define SDL_tcsstr SDL_wcsstr
  96. #else
  97. #define WIN_StringToUTF8 WIN_StringToUTF8A
  98. #define WIN_UTF8ToString WIN_UTF8ToStringA
  99. #define SDL_tcslen SDL_strlen
  100. #define SDL_tcsstr SDL_strstr
  101. #endif
  102. // Set up for C function definitions, even when using C++
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. // Sets an error message based on a given HRESULT
  107. extern bool WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr);
  108. // Sets an error message based on GetLastError(). Always returns false.
  109. extern bool WIN_SetError(const char *prefix);
  110. // Load a function from combase.dll
  111. FARPROC WIN_LoadComBaseFunction(const char *name);
  112. // Wrap up the oddities of CoInitialize() into a common function.
  113. extern HRESULT WIN_CoInitialize(void);
  114. extern void WIN_CoUninitialize(void);
  115. // Wrap up the oddities of RoInitialize() into a common function.
  116. extern HRESULT WIN_RoInitialize(void);
  117. extern void WIN_RoUninitialize(void);
  118. // Returns true if we're running on Windows XP (any service pack). DOES NOT CHECK XP "OR GREATER"!
  119. extern BOOL WIN_IsWindowsXP(void);
  120. // Returns true if we're running on Windows Vista and newer
  121. extern BOOL WIN_IsWindowsVistaOrGreater(void);
  122. // Returns true if we're running on Windows 7 and newer
  123. extern BOOL WIN_IsWindows7OrGreater(void);
  124. // Returns true if we're running on Windows 8 and newer
  125. extern BOOL WIN_IsWindows8OrGreater(void);
  126. // You need to SDL_free() the result of this call.
  127. extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);
  128. // Checks to see if two GUID are the same.
  129. extern BOOL WIN_IsEqualGUID(const GUID *a, const GUID *b);
  130. extern BOOL WIN_IsEqualIID(REFIID a, REFIID b);
  131. // Convert between SDL_rect and RECT
  132. extern void WIN_RECTToRect(const RECT *winrect, SDL_Rect *sdlrect);
  133. extern void WIN_RectToRECT(const SDL_Rect *sdlrect, RECT *winrect);
  134. // Returns false if a window client rect is not valid
  135. bool WIN_WindowRectValid(const RECT *rect);
  136. extern SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat);
  137. // WideCharToMultiByte, but with some WinXP management.
  138. extern int WIN_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
  139. // Ends C function definitions when using C++
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif // _INCLUDED_WINDOWS_H