soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SBStr.cpp
1#ifdef _WIN32
2
3#include "souistd.h"
4#include "activex/SBStr.h"
5
6SNSBEGIN
7sbstr::sbstr(const char16 *non_bstr)
8 : bstr_(SysAllocString(non_bstr))
9{
10}
11
12sbstr::sbstr(int nSize, const char16 *non_bstr)
13{
14 if (nSize == 0)
15 {
16 bstr_ = NULL;
17 }
18 else
19 {
20 bstr_ = ::SysAllocStringLen(non_bstr, nSize);
21 }
22}
23
24sbstr::~sbstr()
25{
26 SysFreeString(bstr_);
27}
28
29void sbstr::Reset(BSTR bstr)
30{
31 if (bstr != bstr_)
32 {
33 // if |bstr_| is NULL, SysFreeString does nothing.
34 SysFreeString(bstr_);
35 bstr_ = bstr;
36 }
37}
38
39BSTR sbstr::Release()
40{
41 BSTR bstr = bstr_;
42 bstr_ = NULL;
43 return bstr;
44}
45
46void sbstr::Swap(sbstr &bstr2)
47{
48 BSTR tmp = bstr_;
49 bstr_ = bstr2.bstr_;
50 bstr2.bstr_ = tmp;
51}
52
53BSTR *sbstr::Receive()
54{
55 return &bstr_;
56}
57
58BSTR sbstr::Allocate(const char16 *str)
59{
60 Reset(SysAllocString(str));
61 return bstr_;
62}
63
64BSTR sbstr::AllocateBytes(size_t bytes)
65{
66 Reset(SysAllocStringByteLen(NULL, static_cast<UINT>(bytes)));
67 return bstr_;
68}
69
70void sbstr::SetByteLen(size_t bytes)
71{
72 uint32 *data = reinterpret_cast<uint32 *>(bstr_);
73 data[-1] = static_cast<uint32>(bytes);
74}
75
76size_t sbstr::Length() const
77{
78 return SysStringLen(bstr_);
79}
80
81size_t sbstr::ByteLength() const
82{
83 return SysStringByteLen(bstr_);
84}
85
86SNSEND
87
88#endif //_WIN32