diff options
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/c/common.h b/c/common.h new file mode 100644 index 0000000..a6bba23 --- /dev/null +++ b/c/common.h @@ -0,0 +1,59 @@ +#ifndef COMMON_H +#define COMMON_H + +#include <memory> +#include <optional> +#include <stdexcept> +#include <windows.h> + +TCHAR *TszFromSz(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 |