4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_Foundation_Common_Platform_Windows
9#error "WINDOWS REQUIRED FOR THIS MODULE"
13#include "Stroika/Foundation/Execution/Throw.h"
26string Characters::Platform::Windows::BSTRStringToUTF8 (
const BSTR bstr)
28 if (bstr ==
nullptr) {
32 int srcStrLen = ::SysStringLen (bstr);
33 int stringLength = ::WideCharToMultiByte (WellKnownCodePages::kUTF8, 0, bstr, srcStrLen,
nullptr, 0,
nullptr,
nullptr);
35 result.resize (stringLength);
36 Verify (::WideCharToMultiByte (WellKnownCodePages::kUTF8, 0, bstr, srcStrLen,
Containers::Start (result), stringLength,
nullptr,
37 nullptr) == stringLength);
47BSTR Characters::Platform::Windows::UTF8StringToBSTR (
const char* ws)
50 size_t wsLen = ::strlen (ws);
51 int stringLength = ::MultiByteToWideChar (CP_UTF8, 0, ws,
static_cast<int> (wsLen),
nullptr, 0);
52 BSTR result = ::SysAllocStringLen (
nullptr, stringLength);
53 if (result ==
nullptr) [[unlikely]] {
56 Verify (::MultiByteToWideChar (WellKnownCodePages::kUTF8, 0, ws,
static_cast<int> (wsLen), result, stringLength) == stringLength);
65wstring Characters::Platform::Windows::BSTR2wstring (VARIANT b)
67 if (b.vt == VT_BSTR) {
68 return BSTR2wstring (b.bstrVal);
80void PlatformCodePageConverter::MapToUNICODE (
const char* inMBChars,
size_t inMBCharCnt,
wchar_t* outChars,
size_t* outCharCnt)
const
82 Require (inMBCharCnt == 0 or inMBChars !=
nullptr);
84 Require (*outCharCnt == 0 or outChars !=
nullptr);
86 *outCharCnt = ::MultiByteToWideChar (fCodePage_, 0, inMBChars,
static_cast<int> (inMBCharCnt), outChars,
static_cast<int> (*outCharCnt));
93 if (*outCharCnt == 0) {
94 DWORD x = GetLastError ();
100void PlatformCodePageConverter::MapFromUNICODE (
const wchar_t* inChars,
size_t inCharCnt,
char* outChars,
size_t* outCharCnt)
const
102 Require (inCharCnt == 0 or inChars !=
nullptr);
104 Require (*outCharCnt == 0 or outChars !=
nullptr);
106 ::WideCharToMultiByte (fCodePage_, 0, inChars,
static_cast<int> (inCharCnt), outChars,
static_cast<int> (*outCharCnt),
nullptr,
nullptr);
#define RequireNotNull(p)
CONTAINER::value_type * Start(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the start of the ...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...