aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h30
1 files changed, 17 insertions, 13 deletions
diff --git a/c/common.h b/c/common.h
index 738368f..4b28360 100644
--- a/c/common.h
+++ b/c/common.h
@@ -6,7 +6,14 @@
#include <stdexcept>
#include <windows.h>
+#ifdef UNICODE
+#define WA "W"
+#else
+#define WA "A"
+#endif
+
std::basic_string<TCHAR> TsmFromSz(const char *, int);
+
struct Win32Error : public std::exception
{
Win32Error(DWORD);
@@ -16,6 +23,7 @@ private:
DWORD m_dwErr;
char *m_szMsg = NULL;
};
+
struct Library
{
Library(const TCHAR *);
@@ -25,32 +33,28 @@ 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;
+ if (a == b) return 0;
+ if (a > b) return 1;
return -1;
}
+/* Return integer scaled for current DPI. */
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)
+/* 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 <class C, typename ...T>
+std::optional<C> try_make(T ...args)
{
try {
- return T(args...);
+ return C(args...);
} catch (...) {
return {};
}