aboutsummaryrefslogtreecommitdiff
path: root/c/common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/common.cpp')
-rw-r--r--c/common.cpp18
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
{