blob: 738368ffc8c188ed1214da029e3b44954990db00 (
plain)
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
|
#ifndef COMMON_H
#define COMMON_H
#include <memory>
#include <optional>
#include <stdexcept>
#include <windows.h>
std::basic_string<TCHAR> TsmFromSz(const char *, int);
struct Win32Error : public std::exception
{
Win32Error(DWORD);
~Win32Error(void);
virtual const char *what(void) const noexcept override;
private:
DWORD m_dwErr;
char *m_szMsg = NULL;
};
struct Library
{
Library(const TCHAR *);
~Library(void);
FARPROC GetProcAddress(const char *);
private:
HMODULE m_hModule;
};
#ifdef UNICODE
#define WA "W"
#else
#define WA "A"
#endif
inline int Cmp(int a, int b)
{
if (a == b)
return 0;
if (a > b)
return 1;
return -1;
}
inline int Dpi(int i)
{
extern int g_iDPI;
return MulDiv(i, g_iDPI, 96);
}
template <class T, typename ...A>
std::optional<T> try_make(A ...args)
{
try {
return T(args...);
} catch (...) {
return {};
}
}
#endif
|