From e2dfdd7d07f54b464a4419dcf102662f1694d4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 15 Jul 2022 18:50:15 +0200 Subject: Split defs.h into separate header files. This is feasible now that the makedeps script exists to automatically manage build dependencies (see 6034fe2, d00f8b3). --- c/common.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 c/common.h (limited to 'c/common.h') 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 +#include +#include +#include + +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 +std::optional try_make(A ...args) +{ + try { + return T(args...); + } catch (...) { + return {}; + } +} + +#endif -- cgit v1.2.3