aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-15 18:50:15 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-15 18:50:15 +0200
commite2dfdd7d07f54b464a4419dcf102662f1694d4b8 (patch)
tree7c8ef515847be96cdb12ddc21b8a3104fcce9428 /c/common.h
parent450770c00ae724fa8a3dc05fc86bf414cfa34e2f (diff)
downloadEpisodeBrowser-e2dfdd7d07f54b464a4419dcf102662f1694d4b8.tar.gz
Split defs.h into separate header files.
This is feasible now that the makedeps script exists to automatically manage build dependencies (see 6034fe2, d00f8b3).
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h59
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