2 * Copyright 2016 Józef Kucia for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef __VKD3D_WINDOWS_H
20 #define __VKD3D_WINDOWS_H
24 #ifndef __C89_NAMELESS
25 # ifdef NONAMELESSUNION
26 # define __C89_NAMELESS
27 # define __C89_NAMELESSUNIONNAME u
29 # define __C89_NAMELESS
30 # define __C89_NAMELESSUNIONNAME
31 # endif /* NONAMELESSUNION */
32 #endif /* __C89_NAMELESS */
34 #if !defined(_WIN32) || defined(__WIDL__)
36 # if !defined(__WIDL__) && !defined(VKD3D_WIN32_WCHAR)
41 # define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
46 # define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
47 # define FAILED(hr) ((HRESULT)(hr) < 0)
49 # define _HRESULT_TYPEDEF_(x) ((HRESULT)x)
51 # define S_OK _HRESULT_TYPEDEF_(0)
52 # define S_FALSE _HRESULT_TYPEDEF_(1)
54 # define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001)
55 # define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002)
56 # define E_POINTER _HRESULT_TYPEDEF_(0x80004003)
57 # define E_ABORT _HRESULT_TYPEDEF_(0x80004004)
58 # define E_FAIL _HRESULT_TYPEDEF_(0x80004005)
59 # define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000E)
60 # define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057)
62 # define DXGI_ERROR_NOT_FOUND _HRESULT_TYPEDEF_(0x887a0002)
63 # define DXGI_ERROR_MORE_DATA _HRESULT_TYPEDEF_(0x887a0003)
66 typedef unsigned char BYTE
;
67 typedef unsigned int DWORD
;
69 typedef unsigned int UINT
;
71 typedef unsigned int ULONG
;
75 /* Assuming LP64 model */
77 typedef unsigned char UINT8
;
79 typedef unsigned short UINT16
;
81 typedef unsigned int UINT32
;
82 # if defined(__x86_64__) || defined(__WIDL__)
84 typedef unsigned long UINT64
;
86 typedef long long DECLSPEC_ALIGN(8) INT64
;
87 typedef unsigned long long DECLSPEC_ALIGN(8) UINT64
;
89 typedef long LONG_PTR
;
90 typedef unsigned long ULONG_PTR
;
92 typedef ULONG_PTR SIZE_T
;
94 # ifdef VKD3D_WIN32_WCHAR
95 typedef unsigned short WCHAR
;
97 typedef wchar_t WCHAR
;
98 # endif /* VKD3D_WIN32_WCHAR */
106 unsigned short Data2
;
107 unsigned short Data3
;
108 unsigned char Data4
[8];
114 unsigned short Data2
;
115 unsigned short Data3
;
116 unsigned char Data4
[8];
124 # define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
125 const GUID name DECLSPEC_HIDDEN; \
127 { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 }}
129 # define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
130 EXTERN_C const GUID name DECLSPEC_HIDDEN; \
131 EXTERN_C const GUID name = \
132 { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 }}
135 # define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
136 EXTERN_C const GUID name DECLSPEC_HIDDEN;
137 # endif /* INITGUID */
139 /* __uuidof emulation */
140 #if defined(__cplusplus) && !defined(_MSC_VER)
144 template<typename T
> const GUID
&__vkd3d_uuidof();
147 # define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
150 template<> inline const GUID &__vkd3d_uuidof<type>() \
152 static const IID __uuid_inst = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \
153 return __uuid_inst; \
155 template<> inline const GUID &__vkd3d_uuidof<type *>() \
157 return __vkd3d_uuidof<type>(); \
161 # define __uuidof(type) __vkd3d_uuidof<typeof(type)>()
163 # define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
164 #endif /* defined(__cplusplus) && !defined(_MSC_VER) */
166 typedef struct SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
;
167 #endif /* !defined(_WIN32) || defined(__WIDL__) */
175 # define COM_NO_WINDOWS_H
177 # define FORCEINLINE inline
179 # define CONTAINING_RECORD(address, type, field) \
180 ((type *)((char *)(address) - offsetof(type, field)))
183 # define __stdcall __attribute__((ms_abi))
185 # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || defined(__APPLE__)
186 # define __stdcall __attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))
188 # define __stdcall __attribute__((__stdcall__))
192 # define WINAPI __stdcall
193 # define STDMETHODCALLTYPE __stdcall
196 # define DECLSPEC_SELECTANY __attribute__((weak))
199 /* Macros for COM interfaces */
200 # define interface struct
201 # define BEGIN_INTERFACE
202 # define END_INTERFACE
203 # define MIDL_INTERFACE(x) struct
206 # define EXTERN_C extern "C"
208 # define EXTERN_C extern
211 # define CONST_VTBL const
216 # if defined(__cplusplus) && !defined(CINTERFACE)
217 # define REFIID const IID &
218 # define REFGUID const GUID &
220 # define REFIID const IID * const
221 # define REFGUID const GUID * const
224 #if defined(__cplusplus) && !defined(CINTERFACE)
225 # define IsEqualGUID(guid1, guid2) (!memcmp(&(guid1), &(guid2), sizeof(GUID)))
227 # define IsEqualGUID(guid1, guid2) (!memcmp(guid1, guid2, sizeof(GUID)))
230 #elif !defined(__WIDL__)
232 # include <windows.h>
237 /* Define DECLSPEC_HIDDEN */
238 #ifndef DECLSPEC_HIDDEN
239 # if defined(__MINGW32__)
240 # define DECLSPEC_HIDDEN
241 # elif defined(__GNUC__)
242 # define DECLSPEC_HIDDEN __attribute__((visibility("hidden")))
244 # define DECLSPEC_HIDDEN
246 #endif /* DECLSPEC_HIDDEN */
248 /* Define min() & max() macros */
251 # define min(a, b) (((a) <= (b)) ? (a) : (b))
255 # define max(a, b) (((a) >= (b)) ? (a) : (b))
257 #endif /* NOMINMAX */
259 #ifndef DEFINE_ENUM_FLAG_OPERATORS
261 # define DEFINE_ENUM_FLAG_OPERATORS(type) \
264 inline type operator &(type x, type y) { return (type)((int)x & (int)y); } \
265 inline type operator &=(type &x, type y) { return (type &)((int &)x &= (int)y); } \
266 inline type operator ~(type x) { return (type)~(int)x; } \
267 inline type operator |(type x, type y) { return (type)((int)x | (int)y); } \
268 inline type operator |=(type &x, type y) { return (type &)((int &)x |= (int)y); } \
269 inline type operator ^(type x, type y) { return (type)((int)x ^ (int)y); } \
270 inline type operator ^=(type &x, type y) { return (type &)((int &)x ^= (int)y); } \
273 # define DEFINE_ENUM_FLAG_OPERATORS(type)
275 #endif /* DEFINE_ENUM_FLAG_OPERATORS */
277 #endif /* _INC_WINDOWS */
278 #endif /* __VKD3D_WINDOWS_H */