-
Notifications
You must be signed in to change notification settings - Fork 0
/
bstr.hpp
65 lines (54 loc) · 1.09 KB
/
bstr.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
// windows
#include <windows.h>
#include <oleauto.h>
namespace rap
{
class bstr
{
public:
bstr()
: _str(nullptr)
{ }
bstr(const bstr& that)
: _str(::SysAllocString(that._str))
{ }
bstr(bstr&& that)
: _str(that._str)
{
that._str = nullptr;
}
~bstr()
{
::SysFreeString(this->_str);
this->_str = nullptr;
}
bstr& operator=(const bstr& that)
{
::SysFreeString(this->_str);
this->_str = ::SysAllocString(that._str);
return *this;
}
bstr& operator=(bstr&& that)
{
::SysFreeString(this->_str);
this->_str = that._str;
that._str = nullptr;
return *this;
}
BSTR* operator&()
{
return &_str;
}
::BSTR get()
{
return _str;
}
const ::BSTR get() const
{
return _str;
}
private:
::BSTR _str;
};
}