#ifndef COMMON_H #define COMMON_H #include #include #include #ifdef UNICODE #define WA "W" #else #define WA "A" #endif 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; }; inline int Cmp(const int a, const int b) { if (a == b) return 0; if (a > b) return 1; return -1; } /* Return integer scaled for current DPI. */ inline int Dpi(const int i) { extern int g_iDPI; return MulDiv(i, g_iDPI, 96); } /* Create and return an object of type C. If construction fails, * return nothing. The returned value must be checked before being * used, as dereferencing is undefined if the value is empty. */ template std::optional try_make(T ...args) { try { return C(args...); } catch (...) { return {}; } } #endif