共用方式為


IDebugProperty3::GetStringChars

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

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其中會傳回實際儲存在緩衝區中的字元數。 (Can be NULL in C++.)

傳回值

如果成功的話,會傳回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);

}

請參閱

參考

IDebugProperty3::GetStringCharLength

IDebugProperty3

IDebugProperty2