在用户提供的缓冲区检索该字符串与此属性关联并将其存储。
HRESULT GetStringChars(
ULONG buflen,
WCHAR* rgString,
ULONG* pceltFetched
);
int GetStringChars(
uint buflen,
out string rgString,
out uint pceltFetched
);
参数
buflen
[in] 用户提供的缓冲区可以容纳的最大字符数。rgString
[out] 返回字符串。只有 C++ [], rgString 是指向接收该字符串的 Unicode 字符的缓冲区。 此缓冲区的大小必须至少 buflen 字符 (不是字节)。
pceltFetched
[out] 在缓冲区实际存储的字符数返回。 (可以是 C++ 中的 NULL 。)
返回值
如果成功,则返回; S_OK否则返回错误代码。
备注
在 C++ 中,必须注意确保缓冲区长度至少 buflen Unicode 字符。 请注意 Unicode 字符长度为 2 字节。
备注
在 C++ 中,则返回的字符串不包含一个 null 字符)。如果为, pceltFetched 在字符串中指定的字符数。
示例
[cpp]
CStringW RetrievePropertyString(IDebugProperty2 *pPropInfo)
{
CStringW returnString = L"";
CComQIPtr<IDebugProperty3> pProp3 = pPropInfo->pProperty;
If (pProp3 != NULL) {
ULONG dwStrLen = 0;
HRESULT hr;
hr = pProp3->GetStringCharLength(&dwStrLen);
if (SUCCEEDED(hr) && dwStrLen > 0) {
ULONG dwRead;
CStrBufW buf(returnString,dwStrLen,CStrBuf::SET_LENGTH);
hr = pProp3->GetStringChars(dwStrLen,
reinterpret_cast<WCHAR*>(static_cast<CStringW::PXSTR>(buf)),
&dwRead);
}
}
return(returnString);
}