Path: blob/master/thirdparty/sdl/core/windows/SDL_windows.h
9905 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021// This is an include file for windows.h with the SDL build settings2223#ifndef _INCLUDED_WINDOWS_H24#define _INCLUDED_WINDOWS_H2526#ifdef SDL_PLATFORM_WIN3227#ifndef WIN32_LEAN_AND_MEAN28#define WIN32_LEAN_AND_MEAN 129#endif30#ifndef STRICT31#define STRICT 132#endif33#ifndef UNICODE34#define UNICODE 135#endif36#undef WINVER37#undef _WIN32_WINNT38#if defined(SDL_VIDEO_RENDER_D3D12) || defined(HAVE_DXGI1_6_H)39#define _WIN32_WINNT 0xA00 // For D3D12, 0xA00 is required40#elif defined(HAVE_SHELLSCALINGAPI_H)41#define _WIN32_WINNT 0x603 // For DPI support42#else43#define _WIN32_WINNT 0x501 // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input44#endif45#define WINVER _WIN32_WINNT4647#elif defined(SDL_PLATFORM_WINGDK)48#ifndef WIN32_LEAN_AND_MEAN49#define WIN32_LEAN_AND_MEAN 150#endif51#ifndef STRICT52#define STRICT 153#endif54#ifndef UNICODE55#define UNICODE 156#endif57#undef WINVER58#undef _WIN32_WINNT59#define _WIN32_WINNT 0xA0060#define WINVER _WIN32_WINNT6162#elif defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)63#ifndef WIN32_LEAN_AND_MEAN64#define WIN32_LEAN_AND_MEAN 165#endif66#ifndef STRICT67#define STRICT 168#endif69#ifndef UNICODE70#define UNICODE 171#endif72#undef WINVER73#undef _WIN32_WINNT74#define _WIN32_WINNT 0xA0075#define WINVER _WIN32_WINNT76#endif7778// See https://github.com/libsdl-org/SDL/pull/760779// force_align_arg_pointer attribute requires gcc >= 4.2.x.80#if defined(__clang__)81#define HAVE_FORCE_ALIGN_ARG_POINTER82#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))83#define HAVE_FORCE_ALIGN_ARG_POINTER84#endif85#if defined(__GNUC__) && defined(__i386__) && defined(HAVE_FORCE_ALIGN_ARG_POINTER)86#define MINGW32_FORCEALIGN __attribute__((force_align_arg_pointer))87#else88#define MINGW32_FORCEALIGN89#endif9091#include <windows.h>92#include <basetyps.h> // for REFIID with broken mingw.org headers93#include <mmreg.h>9495// Routines to convert from UTF8 to native Windows text96#define WIN_StringToUTF8W(S) SDL_iconv_string("UTF-8", "UTF-16LE", (const char *)(S), (SDL_wcslen(S) + 1) * sizeof(WCHAR))97#define WIN_UTF8ToStringW(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (const char *)(S), SDL_strlen(S) + 1)98// !!! FIXME: UTF8ToString() can just be a SDL_strdup() here.99#define WIN_StringToUTF8A(S) SDL_iconv_string("UTF-8", "ASCII", (const char *)(S), (SDL_strlen(S) + 1))100#define WIN_UTF8ToStringA(S) SDL_iconv_string("ASCII", "UTF-8", (const char *)(S), SDL_strlen(S) + 1)101#if UNICODE102#define WIN_StringToUTF8 WIN_StringToUTF8W103#define WIN_UTF8ToString WIN_UTF8ToStringW104#define SDL_tcslen SDL_wcslen105#define SDL_tcsstr SDL_wcsstr106#else107#define WIN_StringToUTF8 WIN_StringToUTF8A108#define WIN_UTF8ToString WIN_UTF8ToStringA109#define SDL_tcslen SDL_strlen110#define SDL_tcsstr SDL_strstr111#endif112113// Set up for C function definitions, even when using C++114#ifdef __cplusplus115extern "C" {116#endif117118// Sets an error message based on a given HRESULT119extern bool WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr);120121// Sets an error message based on GetLastError(). Always returns false.122extern bool WIN_SetError(const char *prefix);123124// Load a function from combase.dll125FARPROC WIN_LoadComBaseFunction(const char *name);126127// Wrap up the oddities of CoInitialize() into a common function.128extern HRESULT WIN_CoInitialize(void);129extern void WIN_CoUninitialize(void);130131// Wrap up the oddities of RoInitialize() into a common function.132extern HRESULT WIN_RoInitialize(void);133extern void WIN_RoUninitialize(void);134135// Returns true if we're running on Windows XP (any service pack). DOES NOT CHECK XP "OR GREATER"!136extern BOOL WIN_IsWindowsXP(void);137138// Returns true if we're running on Windows Vista and newer139extern BOOL WIN_IsWindowsVistaOrGreater(void);140141// Returns true if we're running on Windows 7 and newer142extern BOOL WIN_IsWindows7OrGreater(void);143144// Returns true if we're running on Windows 8 and newer145extern BOOL WIN_IsWindows8OrGreater(void);146147// You need to SDL_free() the result of this call.148extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);149150// Checks to see if two GUID are the same.151extern BOOL WIN_IsEqualGUID(const GUID *a, const GUID *b);152extern BOOL WIN_IsEqualIID(REFIID a, REFIID b);153154// Convert between SDL_rect and RECT155extern void WIN_RECTToRect(const RECT *winrect, SDL_Rect *sdlrect);156extern void WIN_RectToRECT(const SDL_Rect *sdlrect, RECT *winrect);157158// Returns false if a window client rect is not valid159bool WIN_WindowRectValid(const RECT *rect);160161extern SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat);162163// WideCharToMultiByte, but with some WinXP management.164extern int WIN_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);165166// Ends C function definitions when using C++167#ifdef __cplusplus168}169#endif170171#endif // _INCLUDED_WINDOWS_H172173174