diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-26 19:27:35 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-26 19:27:35 +0200 |
commit | 547cbe578dcdb5aa5cfdac1cdb327f92bad21219 (patch) | |
tree | dc41dc107559a3ac2c87669b3616d8a33d221180 /c/common.h | |
parent | dccea47e9bc322d654902a1db4fc52cbf6dd0cd7 (diff) | |
download | EpisodeBrowser-547cbe578dcdb5aa5cfdac1cdb327f92bad21219.tar.gz |
Remove ANSI compatibility.
Even though it is a fun challange in many ways, I think that,
realistically, it is probably not worth the complexity. The
Prolog backend isn't ANSI-compatible either.
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 39 |
1 files changed, 6 insertions, 33 deletions
@@ -11,51 +11,25 @@ #define WA "A" #endif -template <typename T> std::basic_string<T> BstrFromSz(const char* sz, int iCp = CP_UTF8); -int EBMessageBox(const TCHAR* tszText, const TCHAR* tszCaption, unsigned uType); - -/* Conditionally choose between two values. */ -template <bool B, typename X, typename Y> -constexpr std::enable_if_t<B == true, X> choose(X x, Y) { return x; } -template <bool B, typename X, typename Y> -constexpr std::enable_if_t<B == false, Y> choose(X, Y y) { return y; } - -/* Conditionally choose between ANSI and wide string literal. */ -#define AWTEXT(t, s) choose<std::is_same_v<t, wchar_t>>(L"" s, s) - -/* Conditionally choose between ANSI and wide Windows API function. */ -#define AWFUN(t, f) choose<std::is_same_v<t, wchar_t>>(f##W, f##A) +std::wstring WstrFromSz(const char* sz, int iCp = CP_UTF8); +int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType); struct Win32Error : public std::exception { Win32Error(); Win32Error(DWORD dwErr); ~Win32Error(); - template <typename T = char> const T* what() const noexcept; + const char* what() const noexcept; + const wchar_t* WhatW() const noexcept; DWORD dwErr; private: char* m_szMsg = NULL; wchar_t* m_wszMsg = NULL; }; -template <typename T> -const T* Win32Error::what() const noexcept -{ - TCHAR* tszMsg = choose<std::is_same_v<T, wchar_t>>(m_wszMsg, m_szMsg); - if (!tszMsg) - AWFUN(T, FormatMessage)( - FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwErr, - MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), - (TCHAR*)&tszMsg, - 0, NULL); - return tszMsg; -} - struct Library { - Library(const TCHAR* tszLibrary); + Library(const wchar_t* wszLibrary); ~Library(); template <class T> T* GetProcAddress(const char* szProc); private: @@ -98,8 +72,7 @@ template <typename T> inline T prefer(const T x) { if (!x) { - EBMessageBox(Win32Error().what<TCHAR>(), - TEXT("System Error"), MB_ICONWARNING); + EBMessageBox(Win32Error().WhatW(), L"System Error", MB_ICONWARNING); return (T)NULL; } return x; |