ezEngine  Milestone 7
Platform_win.h
1 #pragma once
2 
3 #if EZ_DISABLED(EZ_PLATFORM_WINDOWS)
4  #error "This header should only be included on windows platforms
5 #endif
6 
7 #ifdef _WIN64
8  #undef EZ_PLATFORM_64BIT
9  #define EZ_PLATFORM_64BIT EZ_ON
10 #else
11  #undef EZ_PLATFORM_32BIT
12  #define EZ_PLATFORM_32BIT EZ_ON
13 #endif
14 
15 #ifndef _CRT_SECURE_NO_WARNINGS
16  #define _CRT_SECURE_NO_WARNINGS
17 #endif
18 
19 #include <winsock2.h>
20 
21 #include <Windows.h>
22 #include <Shellapi.h>
23 #include <Rpc.h>
24 
25 #include <crtdbg.h>
26 
27 #include <malloc.h>
28 
29 // unset windows macros
30 #undef min
31 #undef max
32 #undef GetObject
33 #undef GetCommandLine
34 #undef ERROR
35 #undef CreateWindow
36 #undef DeleteFile
37 #undef CreateDirectory
38 #undef CopyFile
39 #undef DispatchMessage
40 #undef PostMessage
41 #undef SendMessage
42 
43 #if defined(_MSC_VER)
44 
45  #undef EZ_COMPILER_MSVC
46  #define EZ_COMPILER_MSVC EZ_ON
47 
48  #ifdef _DEBUG
49  #undef EZ_COMPILE_FOR_DEBUG
50  #define EZ_COMPILE_FOR_DEBUG EZ_ON
51  #endif
52 
53  #define EZ_ANALYSIS_ASSUME(code_to_be_true) __analysis_assume(code_to_be_true)
54  #define EZ_ANALYSIS_IGNORE_WARNING_ONCE(x) __pragma(warning(suppress:x))
55  #define EZ_ANALYSIS_IGNORE_WARNING_START(x) __pragma(warning(push)) __pragma(warning(disable:x))
56  #define EZ_ANALYSIS_IGNORE_WARNING_END __pragma(warning(pop))
57  #define EZ_ANALYSIS_IGNORE_ALL_START __pragma(warning(push)) __pragma(warning(disable: 4251 6001 6011 6031 6211 6246 6326 6385 6386 6387 6540))
58  #define EZ_ANALYSIS_IGNORE_ALL_END __pragma(warning(pop))
59 
60  // On MSVC 2008 in 64 Bit "intin.h" generates a lot of warnings
61  #define EZ_MSVC_WARNING_NUMBER 4985
62  #include <Foundation/Basics/Compiler/DisableWarning.h>
63 
64  EZ_ANALYSIS_IGNORE_WARNING_START(6540)
65  #include <intrin.h>
66  EZ_ANALYSIS_IGNORE_WARNING_END
67 
68  #include <Foundation/Basics/Compiler/RestoreWarning.h>
69 
70  #define EZ_FORCE_INLINE __forceinline
71  #define EZ_RESTRICT __restrict
72 
73 
74  #ifdef __INTELLISENSE__
75  #define EZ_ALIGN(decl, alignment) decl
76  #else
77  #define EZ_ALIGN(decl, alignment) __declspec(align(alignment)) decl
78  #endif
79 
80  // workaround for msvc compiler issue with alignment determination of dependent types
81  #define EZ_ALIGNMENT_OF(type) EZ_COMPILE_TIME_MIN(sizeof(type), __alignof(type))
82 
83  #define EZ_DEBUG_BREAK { __debugbreak(); }
84 
85  #define EZ_SOURCE_FUNCTION __FUNCTION__
86  #define EZ_SOURCE_LINE __LINE__
87  #define EZ_SOURCE_FILE __FILE__
88 
89  // declare platform specific types
90  typedef unsigned __int64 ezUInt64;
91  typedef __int64 ezInt64;
92 
93  // Set Warnings as Errors: Too few/many parameters given for Macro
94  #pragma warning(error : 4002 4003)
95 
96  // Enable 'symbol' is not defined as a preprocessor macro
97  // #pragma warning(3 : 4668)
98 
99  // class 'type' needs to have dll-interface to be used by clients of class 'type2' -> dll export / import issues (mostly with templates)
100  #pragma warning(disable: 4251)
101 
102  // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
103  #pragma warning(disable: 4345)
104 
105  // EZ_VA_NUM_ARGS() is a very nifty macro to retrieve the number of arguments handed to a variable-argument macro
106  // unfortunately, VS 2010 still has this compiler bug which treats a __VA_ARGS__ argument as being one single parameter:
107  // https://connect.microsoft.com/VisualStudio/feedback/details/521844/variadic-macro-treating-va-args-as-a-single-parameter-for-other-macros#details
108  #if _MSC_VER >= 1400
109  #define EZ_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
110  #define EZ_VA_NUM_ARGS_REVERSE_SEQUENCE 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
111  #define EZ_LEFT_PARENTHESIS (
112  #define EZ_RIGHT_PARENTHESIS )
113  #define EZ_VA_NUM_ARGS(...) EZ_VA_NUM_ARGS_HELPER EZ_LEFT_PARENTHESIS __VA_ARGS__, EZ_VA_NUM_ARGS_REVERSE_SEQUENCE EZ_RIGHT_PARENTHESIS
114  #endif
115 
116  #ifndef va_copy
117  #define va_copy(dest, source) (dest) = (source)
118  #endif
119 
120 #else
121  #error "Unsupported compiler on windows"
122 #endif
123 
124 #undef EZ_PLATFORM_LITTLE_ENDIAN
125 #define EZ_PLATFORM_LITTLE_ENDIAN EZ_ON
126