This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathpch.h
126 lines (104 loc) · 2.72 KB
/
pch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//--------------------------------------------------------------------------------------
// pch.h
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#pragma warning(push)
#pragma warning(disable : 4005)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#define NODRAWTEXT
#define NOBITMAP
#define NOMCX
#define NOSERVICE
#define NOHELP
#pragma warning(pop)
#include <algorithm>
#include <stdio.h>
#include <tchar.h>
#include <exception>
#include <stdint.h>
#include <set>
#include <windows.h>
namespace DX
{
// formatted exception helper class
template<unsigned SIZE>
class exception_fmt : public std::exception
{
public:
exception_fmt(const char *msg, ...)
{
va_list args;
va_start(args, msg);
vsprintf_s(exnBuffer, msg, args);
va_end(args);
}
virtual const char *what() const override
{
return exnBuffer;
}
private:
static thread_local char exnBuffer[SIZE];
};
template<unsigned SIZE>
thread_local char exception_fmt<SIZE>::exnBuffer[SIZE];
// Helper class for Win32 errors
class last_err_exception : public std::exception
{
public:
last_err_exception(uint32_t err)
: result(err) {}
last_err_exception()
: result(0)
{
result = GetLastError();
}
virtual const char *what() const override
{
static char s_str[64] = {};
sprintf_s(s_str, "Failure with last error of %08X", result);
return s_str;
}
private:
uint32_t result;
};
// Convert the last error into an exception
inline void ThrowLastError()
{
throw last_err_exception();
}
template<typename T>
inline void ThrowLastErrWhenFalse(T result)
{
if (!result)
{
throw last_err_exception();
}
}
// Helper class for COM exceptions
class com_exception : public std::exception
{
public:
com_exception(HRESULT hr) noexcept : result(hr) {}
const char* what() const override
{
static char s_str[64] = {};
sprintf_s(s_str, "Failure with HRESULT of %08X", result);
return s_str;
}
private:
HRESULT result;
};
// Helper utility converts D3D API failures into exceptions.
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
throw com_exception(hr);
}
}
} // namespace DX
// TODO: reference additional headers your program requires here