aboutsummaryrefslogtreecommitdiff
path: root/c/win.cpp
diff options
context:
space:
mode:
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";