aboutsummaryrefslogtreecommitdiff
path: root/c/common.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-26 19:27:35 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-26 19:27:35 +0200
commit547cbe578dcdb5aa5cfdac1cdb327f92bad21219 (patch)
treedc41dc107559a3ac2c87669b3616d8a33d221180 /c/common.cpp
parentdccea47e9bc322d654902a1db4fc52cbf6dd0cd7 (diff)
downloadEpisodeBrowser-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.cpp')
-rw-r--r--c/common.cpp45
1 files changed, 32 insertions, 13 deletions
diff --git a/c/common.cpp b/c/common.cpp
index c4624c0..ca8dfac 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -15,11 +15,37 @@ Win32Error::~Win32Error()
HeapFree(GetProcessHeap(), 0, m_wszMsg);
}
+const char* Win32Error::what() const noexcept
+{
+ if (!m_szMsg)
+ FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwErr,
+ MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
+ (char*)&m_szMsg,
+ 0, NULL);
+ return m_szMsg;
+}
+
+const wchar_t* Win32Error::WhatW() const noexcept
+{
+ if (!m_wszMsg)
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwErr,
+ MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
+ (wchar_t*)&m_wszMsg,
+ 0, NULL);
+ return m_wszMsg;
+}
+
/* Library: Wrapper for loading and freeing dynamically linked libraries. */
-Library::Library(const TCHAR* const tszLibrary)
+Library::Library(const wchar_t* const wszLibrary)
{
- m_hModule = LoadLibrary(tszLibrary);
+ m_hModule = LoadLibrary(wszLibrary);
if (!m_hModule)
throw Win32Error();
}
@@ -29,15 +55,8 @@ Library::~Library()
FreeLibrary(m_hModule);
}
-/* Convert narrow unmanaged string to narrow/wide basic string. */
-template <>
-std::basic_string<char> BstrFromSz(const char* sz, int)
-{
- return std::string(sz);
-}
-
-template <>
-std::basic_string<wchar_t> BstrFromSz(const char* sz, int iCp)
+/* Convert narrow unmanaged string to wide managed string. */
+std::wstring WstrFromSz(const char* sz, int iCp)
{
int cbMultiByte = strlen(sz)+1;
int cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0);
@@ -71,11 +90,11 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR
}
/* Show message box owned by and centered in the main window. */
-int EBMessageBox(const TCHAR* const tszText, const TCHAR* const tszCaption, const unsigned uType)
+int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption, const unsigned uType)
{
extern HWND g_hWnd;
HHOOK hHook = require(SetWindowsHookEx(WH_CBT, CBTProc, (HINSTANCE)NULL, GetCurrentThreadId()));
- int r = MessageBox(g_hWnd, tszText, tszCaption, uType);
+ int r = MessageBox(g_hWnd, wszText, wszCaption, uType);
require(UnhookWindowsHookEx(hHook));
return r;
}