7 #ifndef _INC_cWinString_H
8 #define _INC_cWinString_H
13 #include "../GrayLibBase.h"
29 #if defined(_WIN32) && ! defined(_MFC_VER)
51 m_str = ::SysAllocString(pSrc);
60 m_str = ::SysAllocStringLen(pSrc, nLenChars);
71 m_str = ::SysAllocStringLen(
nullptr, iLenChars);
76 m_str =
src.MakeCopy();
80 ::SysFreeString(m_str);
85 if (m_str !=
src.m_str)
87 ::SysFreeString(m_str);
88 m_str =
src.MakeCopy();
97 ::SysFreeString(m_str);
99 m_str = ::SysAllocString(pSrc);
111 return (m_str ==
nullptr) ? 0 : ::SysStringLen(m_str);
114 size_t ByteLength()
const throw()
119 return (m_str ==
nullptr) ? 0 : ::SysStringByteLen(m_str);
131 operator BSTR()
const throw()
135 BSTR MakeCopy()
const throw()
138 if (m_str ==
nullptr)
141 return ::SysAllocStringByteLen((
const char*)m_str, ::SysStringByteLen(m_str));
143 BSTR Copy()
const throw()
147 BSTR* ref_BStr() throw()
158 void Attach(BSTR
src)
throw()
163 ::SysFreeString(m_str);
167 BSTR Detach() throw()
176 ::SysFreeString(m_str);
179 HRESULT CopyTo(VARIANT* pvarDest)
const throw()
184 if (pvarDest !=
nullptr)
186 pvarDest->vt = VT_BSTR;
187 pvarDest->bstrVal = MakeCopy();
188 if (pvarDest->bstrVal ==
nullptr && m_str !=
nullptr)
189 hRes = E_OUTOFMEMORY;
195 HRESULT WriteToStream(IStream* pStream)
throw()
197 ASSERT(pStream !=
nullptr);
198 if (pStream ==
nullptr)
202 ULONG cbStrLen = ULONG(m_str ? ::SysStringByteLen(m_str) +
sizeof(OLECHAR) : 0);
203 HRESULT hRes = pStream->Write((
void*)&cbStrLen,
sizeof(cbStrLen), &cb);
206 return cbStrLen ? pStream->Write((
void*)m_str, cbStrLen, &cb) : S_OK;
208 HRESULT ReadFromStream(IStream* pStream)
throw()
210 ASSERT(pStream !=
nullptr);
211 if (pStream ==
nullptr)
218 HRESULT hRes = pStream->Read((
void*)&cbStrLen,
sizeof(cbStrLen),
nullptr);
219 if ((hRes == S_OK) && (cbStrLen != 0))
223 m_str = ::SysAllocStringByteLen(
nullptr, cbStrLen -
sizeof(OLECHAR));
224 if (m_str ==
nullptr)
225 hRes = E_OUTOFMEMORY;
227 hRes = pStream->Read((
void*)m_str, cbStrLen,
nullptr);
232 LARGE_INTEGER nOffset;
233 nOffset.QuadPart = -(
static_cast<LONGLONG
>(
sizeof(cbStrLen)));
234 pStream->Seek(nOffset, STREAM_SEEK_CUR,
nullptr);
248 #elif defined(_WIN32)
#define HRESULT_WIN32_C(x)
a constant LSTATUS/error_status_t with no check, unlike HRESULT_FROM_WIN32()
Definition: HResult.h:79
#define FAILED(x)
Definition: HResult.h:30
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
void Empty()
Definition: cString.h:193
const THIS_t & operator=(const THIS_t &s)
Definition: cString.h:515
const wchar_t * get_CPtr() const noexcept
Definition: cString.h:419
UNITTEST2_PREDEF(cQuadtree)
cStringW cWinString
Definition: cWinString.h:251
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
const cDebugSourceLine & src
Definition: cDebugAssert.h:51
cUInt64 operator&(const cUInt64 &roUI64_1, const cUInt64 &roUI64_2)
Definition: cUInt64.h:384
static StrLen_t __stdcall UTF8toUNICODELen(const char *pInp, StrLen_t iSizeInpBytes=k_StrLen_UNK)
Definition: StrU.cpp:220
static StrLen_t __stdcall UTF8toUNICODE(wchar_t &wChar, const char *pInp, StrLen_t iSizeInpBytes)
Definition: StrU.cpp:133