HStringReference 类

表示从现有字符串创建的 HSTRING。

语法

class HStringReference;

备注

新 HSTRING 中的后备缓冲区的生存期不由 Windows 运行时管理。 调用方在堆栈帧上分配源字符串,以避免堆分配并消除内存泄漏的风险。 此外,调用方必须确保源字符串在附加的 HSTRING 的生存期内保持不变。 有关详细信息,请参阅 WindowsCreateStringReference 函数

成员

公共构造函数

名称 描述
HStringReference::HStringReference 初始化 HStringReference 类的新实例。

公共方法

成员 说明
HStringReference::CopyTo 将当前 HStringReference 对象复制到 HSTRING 对象。
HStringReference::Get 检索基础 HSTRING 句柄的值。
HStringReference::GetRawBuffer 检索指向基础字符串数据的指针。

公共运算符

“属性” 描述
HStringReference::operator= 将另一个 HStringReference 对象的值移动到当前 HStringReference 对象。
HStringReference::operator== 指示两个参数是否相等。
HStringReference::operator!= 指示两个参数是否不相等。
HStringReference::operator< 指示第一个参数是否小于第二个参数。

继承层次结构

HStringReference

要求

标头:corewrappers.h

命名空间:Microsoft::WRL::Wrappers

HStringReference::CopyTo

将当前 HStringReference 对象复制到 HSTRING 对象。

HRESULT CopyTo(
   _Out_ HSTRING *str
   ) const throw();

参数

str
接收副本的 HSTRING。

注解

此方法调用 WindowsDuplicateString 函数。

HStringReference::Get

检索基础 HSTRING 句柄的值。

HSTRING Get() const throw()

返回值

基础 HSTRING 句柄的值。

HStringReference::GetRawBuffer

检索指向基础字符串数据的指针。

const wchar_t* GetRawBuffer(unsigned int* length) const;

参数

length 指向接收数据长度的 int 变量的指针。

返回值

指向基础字符串数据的 const 指针。

HStringReference::HStringReference

初始化 HStringReference 类的新实例。

template<unsigned int sizeDest>
HStringReference(wchar_t const (&str)[ sizeDest]) throw();

template<unsigned int sizeDest>
HStringReference(wchar_t const (&str)[ sizeDest],
                 unsigned int len) throw();

HStringReference(HStringReference&& other) throw();

参数

sizeDest
指定目标 HStringReference 缓冲区大小的模板参数。

str
对宽字符串的引用。

len
要在此操作中使用的 str 参数缓冲区的最大长度。 如果 len 参数未指定,则将使用整个 str 参数。 如果 len 大于 sizeDest,则 len 设置为 sizeDest-1

其他
另一个 HStringReference 对象。

备注

第一个构造函数初始化大小与参数 str 相同的新的 HStringReference 对象

第二个构造函数初始化大小由参数 len 指定的新的 HStringReference 对象

第三个构造函数将新的 HStringReference 对象初始化为 other 参数的值,然后销毁 other 参数

HStringReference::operator=

将另一个 HStringReference 对象的值移动到当前 HStringReference 对象。

HStringReference& operator=(HStringReference&& other) throw()

参数

其他
一个现有的 HStringReference 对象。

备注

现有 other 对象的值将复制到当前 HStringReference 对象,然后将销毁 other 对象

HStringReference::operator==

指示两个参数是否相等。

inline bool operator==(
               const HStringReference& lhs,
               const HStringReference& rhs) throw()

inline bool operator==(
               const HSTRING& lhs,
               const HStringReference& rhs) throw()

inline bool operator==(
               const HStringReference& lhs,
               const HSTRING& rhs) throw()

参数

lhs
要比较的第一个参数。 lhs 可以是 HStringReference 对象或 HSTRING 句柄

rhs
要比较的第二个参数。 rhs 可以是 HStringReference 对象或 HSTRING 句柄

返回值

如果 lhs 和 rhs 参数相等,则为 true;否则为 false

HStringReference::operator!=

指示两个参数是否不相等。

inline bool operator!=(
               const HStringReference& lhs,
               const HStringReference& rhs) throw()

inline bool operator!=(
               const HSTRING& lhs,
               const HStringReference& rhs) throw()

inline bool operator!=(
               const HStringReference& lhs,
               const HSTRING& rhs) throw()

参数

lhs
要比较的第一个参数。 lhs 可以是 HStringReference 对象或 HSTRING 句柄

rhs
要比较的第二个参数。 rhs 可以是 HStringReference 对象或 HSTRING 句柄

返回值

如果 lhs 和 rhs 参数不相等,则为 true;否则为 false

HStringReference::operator<

指示第一个参数是否小于第二个参数。

inline bool operator<(
    const HStringReference& lhs,
    const HStringReference& rhs) throw()

参数

lhs
要比较的第一个参数。 lhs 可以是对 HStringReference 的引用

rhs
要比较的第二个参数。 rhs 可以是对 HStringReference 的引用

返回值

如果 lhs 参数小于 rhs 参数,则为 true;否则为 false