tests: Add new vkd3d_common test to .gitignore.
[vkd3d.git] / include / vkd3d_windows.h
blob7d63ead75132e7956b9f00d130db3108ddd4855f
1 /*
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
21 #ifndef _INC_WINDOWS
23 /* Nameless unions */
24 #ifndef __C89_NAMELESS
25 # ifdef NONAMELESSUNION
26 # define __C89_NAMELESS
27 # define __C89_NAMELESSUNIONNAME u
28 # else
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)
37 # include <wchar.h>
38 # endif
40 # ifdef __GNUC__
41 # define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
42 # endif
44 /* HRESULT */
45 typedef int HRESULT;
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)
65 /* Basic types */
66 typedef unsigned char BYTE;
67 typedef unsigned int DWORD;
68 typedef int INT;
69 typedef unsigned int UINT;
70 typedef int LONG;
71 typedef unsigned int ULONG;
72 typedef float FLOAT;
73 typedef LONG BOOL;
75 /* Assuming LP64 model */
76 typedef char INT8;
77 typedef unsigned char UINT8;
78 typedef short INT16;
79 typedef unsigned short UINT16;
80 typedef int INT32;
81 typedef unsigned int UINT32;
82 # if defined(__x86_64__) || defined(__WIDL__)
83 typedef long INT64;
84 typedef unsigned long UINT64;
85 # else
86 typedef long long DECLSPEC_ALIGN(8) INT64;
87 typedef unsigned long long DECLSPEC_ALIGN(8) UINT64;
88 # endif
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;
96 # else
97 typedef wchar_t WCHAR;
98 # endif /* VKD3D_WIN32_WCHAR */
99 typedef void *HANDLE;
101 /* GUID */
102 # ifdef __WIDL__
103 typedef struct
105 unsigned long Data1;
106 unsigned short Data2;
107 unsigned short Data3;
108 unsigned char Data4[8];
109 } GUID;
110 # else
111 typedef struct _GUID
113 unsigned int Data1;
114 unsigned short Data2;
115 unsigned short Data3;
116 unsigned char Data4[8];
117 } GUID;
118 # endif
120 typedef GUID IID;
122 # ifdef INITGUID
123 # ifndef __cplusplus
124 # define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
125 const GUID name DECLSPEC_HIDDEN; \
126 const GUID name = \
127 { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 }}
128 # else
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 }}
133 # endif
134 # else
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)
142 extern "C++"
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) \
148 extern "C++" \
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)>()
162 #else
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__) */
170 #ifndef _WIN32
171 # include <stddef.h>
172 # include <stdlib.h>
173 # include <string.h>
175 # define COM_NO_WINDOWS_H
177 # define FORCEINLINE inline
179 # define CONTAINING_RECORD(address, type, field) \
180 ((type *)((char *)(address) - offsetof(type, field)))
182 # ifdef __x86_64__
183 # define __stdcall __attribute__((ms_abi))
184 # else
185 # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || defined(__APPLE__)
186 # define __stdcall __attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))
187 # else
188 # define __stdcall __attribute__((__stdcall__))
189 # endif
190 # endif
192 # define WINAPI __stdcall
193 # define STDMETHODCALLTYPE __stdcall
195 # ifdef __GNUC__
196 # define DECLSPEC_SELECTANY __attribute__((weak))
197 # endif
199 /* Macros for COM interfaces */
200 # define interface struct
201 # define BEGIN_INTERFACE
202 # define END_INTERFACE
203 # define MIDL_INTERFACE(x) struct
205 # ifdef __cplusplus
206 # define EXTERN_C extern "C"
207 # else
208 # define EXTERN_C extern
209 # endif
211 # define CONST_VTBL const
213 # define TRUE 1
214 # define FALSE 0
216 # if defined(__cplusplus) && !defined(CINTERFACE)
217 # define REFIID const IID &
218 # define REFGUID const GUID &
219 # else
220 # define REFIID const IID * const
221 # define REFGUID const GUID * const
222 # endif
224 #if defined(__cplusplus) && !defined(CINTERFACE)
225 # define IsEqualGUID(guid1, guid2) (!memcmp(&(guid1), &(guid2), sizeof(GUID)))
226 #else
227 # define IsEqualGUID(guid1, guid2) (!memcmp(guid1, guid2, sizeof(GUID)))
228 #endif
230 #elif !defined(__WIDL__)
232 # include <windows.h>
234 #endif /* _WIN32 */
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")))
243 # else
244 # define DECLSPEC_HIDDEN
245 # endif
246 #endif /* DECLSPEC_HIDDEN */
248 /* Define min() & max() macros */
249 #ifndef NOMINMAX
250 # ifndef min
251 # define min(a, b) (((a) <= (b)) ? (a) : (b))
252 # endif
254 # ifndef max
255 # define max(a, b) (((a) >= (b)) ? (a) : (b))
256 # endif
257 #endif /* NOMINMAX */
259 #ifndef DEFINE_ENUM_FLAG_OPERATORS
260 #ifdef __cplusplus
261 # define DEFINE_ENUM_FLAG_OPERATORS(type) \
262 extern "C++" \
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); } \
272 #else
273 # define DEFINE_ENUM_FLAG_OPERATORS(type)
274 #endif
275 #endif /* DEFINE_ENUM_FLAG_OPERATORS */
277 #endif /* _INC_WINDOWS */
278 #endif /* __VKD3D_WINDOWS_H */