aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-16 18:27:21 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-16 18:27:21 +0200
commit54570cbc0d6e4798ad47a9db2e726372cfc13297 (patch)
tree2e178a43da331af8881fd2f2ee7709f09f346271 /c/common.h
parentbd812f7d928aa64f837e2fbd23e372ab65d03d87 (diff)
downloadEpisodeBrowser-54570cbc0d6e4798ad47a9db2e726372cfc13297.tar.gz
Formatting.
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 {};
}