次の方法で共有


IDebugProperty3::GetStringChars

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Retrieves the string associated with this property and stores it in a user-supplied buffer.

Syntax

HRESULT GetStringChars(
    ULONG  buflen,
    WCHAR* rgString,
    ULONG* pceltFetched
);
int GetStringChars(
    uint       buflen,
    out string rgString,
    out uint   pceltFetched
);

Parameters

buflen
[in] Maximum number of characters the user-supplied buffer can hold.

rgString
[out] Returns the string.

[C++ only], rgString is a pointer to a buffer that receives the Unicode characters of the string. This buffer must be at least buflen characters (not bytes) in size.

pceltFetched
[out] Where the number of characters actually stored in the buffer is returned. (Can be NULL in C++.)

Return Value

If successful, returns S_OK; otherwise returns an error code.

Remarks

In C++, care must be taken to insure that the buffer is at least buflen Unicode characters long. Note that a Unicode character is 2 bytes long.

Note

In C++, the returned string does not include a terminating null character. If given, pceltFetched will specify the number of characters in the string.

Example

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

See also