aboutsummaryrefslogtreecommitdiff
path: root/c/win.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-24 15:17:08 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-24 15:17:33 +0200
commit6fd66a9264731bd7ee6d7602675965021d929a4a (patch)
treee94fc63efb823ad2f5c9ef6de6188da389a08d38 /c/win.cpp
parentff48d644a45dd71098ecb9007a41807fb37d0081 (diff)
downloadEpisodeBrowser-6fd66a9264731bd7ee6d7602675965021d929a4a.tar.gz
Remove Prolog dependency.
The only thing left to reimplement is the tracking of watched episodes in MPC-HC.
Diffstat (limited to 'c/win.cpp')
-rw-r--r--c/win.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/c/win.cpp b/c/win.cpp
index ba42508..43744dd 100644
--- a/c/win.cpp
+++ b/c/win.cpp
@@ -1,13 +1,21 @@
#include <utility>
#include <string>
-#include <SWI-Prolog.h>
+#include <string_view>
#include <windows.h>
#include <wininet.h>
-#include "pl.h"
#include "util.h"
#include "win.h"
-#include "wcharptr.h"
+
+std::wstring WideFromNarrow(const std::string_view src, const int cp)
+{
+ int cchNarrow = src.length()+1;
+ int cchWide = MultiByteToWideChar(cp, 0, src.data(), cchNarrow, nullptr, 0);
+ std::wstring dst(cchWide, 0);
+ if (!MultiByteToWideChar(cp, 0, src.data(), cchNarrow, dst.data(), cchWide))
+ throw Win32Error();
+ return dst;
+}
void WithNextWindow(void (*proc)(HWND))
{
@@ -87,19 +95,14 @@ void ShowException(const wchar_t* const fmt, const wchar_t* const title, const U
{
try {
std::rethrow_exception(std::current_exception());
- } catch (const term_t& t) {
- WcharPtr what = PlString(t);
- std::wstring msg(wcslen(fmt)+wcslen(what), 0);
- Swprintf(msg, fmt, static_cast<wchar_t*>(what));
- EBMessageBox(msg, title, uType);
} catch (const WideException& e) {
std::wstring msg(wcslen(fmt)+wcslen(e.What()), 0);
Swprintf(msg, fmt, e.What());
EBMessageBox(msg, title, uType);
} catch (const std::exception& e) {
- auto what = WcharPtr::FromNarrow(e.what());
- std::wstring msg(wcslen(fmt)+wcslen(what), 0);
- Swprintf(msg, fmt, static_cast<wchar_t*>(what));
+ std::wstring what = WideFromNarrow(e.what());
+ std::wstring msg(wcslen(fmt)+what.length(), 0);
+ Swprintf(msg, fmt, what.c_str());
EBMessageBox(msg, title, uType);
} catch (...) {
const wchar_t* what = L"an unknown error occurred";