From 6fd66a9264731bd7ee6d7602675965021d929a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 24 Aug 2022 15:17:08 +0200 Subject: Remove Prolog dependency. The only thing left to reimplement is the tracking of watched episodes in MPC-HC. --- c/win.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'c/win.cpp') 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 #include -#include +#include #include #include -#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(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(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"; -- cgit v1.2.3