46 * @brief Give sbstr ownership over an already allocated BSTR or NULL
47 * @param bstr Pointer to the BSTR to take ownership of
48 * If you need to allocate a new BSTR instance, use |Allocate| instead.
49 */
50void Reset(BSTR bstr = NULL);
51
52 /**
53 * @brief Releases ownership of the BSTR to the caller
54 * @return Pointer to the released BSTR
55 */
56 BSTR Release();
57
58 /**
59 * @brief Creates a new BSTR from a wide character string
60 * @param str Pointer to the wide character string
61 * @return Pointer to the new BSTR, or NULL if allocation failed
62 * If you already have a BSTR and want to transfer ownership to the sbstr instance, call |Reset| instead.
63 */
64 BSTR Allocate(const char16 *str);
65
66 /**
67 * @brief Allocates a new BSTR with the specified number of bytes
68 * @param bytes Number of bytes to allocate
69 * @return Pointer to the new BSTR, or NULL if allocation failed
70 */
71 BSTR AllocateBytes(size_t bytes);
72
73 /**
74 * @brief Sets the allocated length field of the already-allocated BSTR to be |bytes|
75 * @param bytes Number of bytes to set as the length
76 * This is useful when the BSTR was preallocated with e.g. SysAllocStringLen or SysAllocStringByteLen (call |AllocateBytes|) and then not all the bytes are being used.
77 * NOTE: The actual allocated size of the BSTR MUST be >= bytes. That responsibility is with the caller.
78 */
79void SetByteLen(size_t bytes);
80
81 /**
82 * @brief Swap values of two sbstr's
83 * @param bstr2 Reference to the sbstr to swap with
84 */
85void Swap(sbstr &bstr2);
86
87 /**
88 * @brief Retrieves the pointer address
89 * @return Pointer to the BSTR pointer
90 * Used to receive BSTRs as out arguments (and take ownership).
91 * The function DCHECKs on the current value being NULL.
92 * Usage: GetBstr(bstr.Receive());
93 */
94 BSTR *Receive();
95
96 /**
97 * @brief Returns the number of characters in the BSTR
98 * @return Number of characters in the BSTR
99 */
100size_t Length() const;
101
102 /**
103 * @brief Returns the number of bytes allocated for the BSTR
104 * @return Number of bytes allocated for the BSTR
105 */
106size_t ByteLength() const;
107
108 /**
109 * @brief Implicit conversion operator to BSTR
110 * @return Pointer to the BSTR
111 */
112operator BSTR() const
113{
114return bstr_;
115 }
116
117protected:
118 BSTR bstr_;
119
120private:
121// Forbid comparison of sbstr types. You should never have the same BSTR owned by two different sbstr instances.