Condividi tramite


IDebugProperty3::GetStringCharLength

Restituisce il numero di caratteri nella stringa della proprietà associata.

Sintassi

int GetStringCharLength(
    out uint pLen
);

Parametri

Parametro Descrizione
pLen [out] Restituisce il numero di caratteri nella stringa della proprietà.

Valore restituito

In caso di esito positivo, restituisce S_OK. In caso contrario, restituisce il codice di errore.

Osservazioni:

In genere, questo metodo viene usato come preludio per allocare un buffer per una chiamata al metodo GetStringChars .

Esempio

Nell'esempio seguente viene illustrato come implementare questo metodo per un oggetto CProperty che espone l'interfaccia IDebugProperty3 .

STDMETHODIMP CProperty::GetStringCharLength(ULONG *pLen)
{
    HRESULT hr = E_INVALIDARG;

    EVALFLAGS oldEVALFLAGS = m_EVALFLAGS;

    m_EVALFLAGS &= ~EVAL_NOFUNCEVAL;

    if (pLen)
    {
        DEBUG_PROPERTY_INFO dpInfo;
        dpInfo.bstrValue = NULL;
        ULONG ulen = 0;
        hr = GetPropertyInfo(DEBUGPROP_INFO_VALUE,10,DEFAULT_TIMEOUT,NULL,0,&dpInfo);
        if (hr == S_OK && dpInfo.bstrValue)
        {
            if (wcscmp(dpInfo.bstrValue,L"Nothing") == 0)
            {
                ulen = 0; //VSWhidbey#64815
            }
            else
            {
                ulen = ::SysStringLen(dpInfo.bstrValue);
                if( ulen > 2 &&
                    dpInfo.bstrValue[0] == L'"' &&
                    dpInfo.bstrValue[ulen-1] == L'"')
                {
                    ulen = ulen > 2 ? ulen - 2 : ulen; //remove two double quotes
                }
            }
        }
        ::SysFreeString(dpInfo.bstrValue);
        *pLen = ulen;
    }
    m_EVALFLAGS = oldEVALFLAGS;
    return hr;
}

Vedi anche