diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-23 18:59:37 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-23 18:59:37 +0200 |
commit | c6cd2f1f164baac1414f2cf658566de146b10552 (patch) | |
tree | cec573bbddacd175f37d8d45e48e8cea80727420 /c/common.cpp | |
parent | 2958c57db73b5af03af36598c9dffc9123a0a003 (diff) | |
download | EpisodeBrowser-c6cd2f1f164baac1414f2cf658566de146b10552.tar.gz |
Fix display of Unicode text.
Turns out that SWI-Prolog's wide string functions, which I started
using in 03fe361, do not convert between narrow Prolog atoms and wide
C strings, as I mistakenly thought. Instead, they work with wide
Prolog atoms. In hindsight, it is not surprising.
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/c/common.cpp b/c/common.cpp index 4ce95a0..155c099 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -57,6 +57,24 @@ 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) +{ + int cbMultiByte = strlen(sz)+1; + int cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0); + std::wstring wstr(cchWideChar, 0); + if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, wstr.data(), cchWideChar)) + throw Win32Error(GetLastError()); + return wstr; +} + /* Move message box to center of main window. */ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPARAM lParam) noexcept { |