IDebugProperty3::GetStringChars

擷取與這個屬性相關聯的字串,並將它儲存在使用者提供的緩衝區中。

語法

int GetStringChars(
    uint       buflen,
    out string rgString,
    out uint   pceltFetched
);

參數

buflen
[in]使用者提供的緩衝區可以保存的最大字元數。

rgString
[out]傳回字串。

[僅限 C++] rgString 是接收字串 Unicode 字元之緩衝區的指標。 此緩衝區的大小至少 buflen 必須是字元(而非位元組)。

pceltFetched
[out]傳回實際儲存在緩衝區中的字元數。 (可以是 NULL C++。

傳回值

如果成功,則會傳回 S_OK;否則會傳回錯誤碼。

備註

在 C++ 中,必須小心確保緩衝區長度至少 buflen 為 Unicode 字元。 請注意,Unicode 字元長度為 2 個字節。

注意

在 C++ 中,傳回的字串不包含終止的 Null 字元。 如果指定, pceltFetched 則會指定字串中的字元數。

範例

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);
}

另請參閱