다음을 통해 공유


로컬 속성 가져오기

호출 Visual Studio IDebugProperty2::EnumChildren 얻을 수는 IEnumDebugPropertyInfo2 표시 하는 모든 지역에 액세스를 제공 하는 개체는 지역 창. Visual Studio 호출 하 고 IEnumDebugPropertyInfo2::Next 각 지역에 대해 표시 되는 정보를 얻을 수 있습니다. 이 예제에서는 클래스 CEnumPropertyInfo 구현에서 IEnumDebugPropertyInfo2 인터페이스입니다.

이 구현의 IEnumDebugPropertyInfo2::Next 다음 작업을 수행 합니다.

  1. 정보를 저장할 수 있는 배열을 지웁니다.

  2. 호출 IEnumDebugFields::Next 각 지역에 대해 반환 되는 저장 DEBUG_PROPERTY_INFO 에서 반환 하는 배열입니다. IEnumDebugFields 개체가 제공 되었습니다 때이 CEnumPropertyInfo 되었습니다 클래스를 인스턴스화합니다.

관리 코드

구현 하는이 예제를 보여 줍니다. IEnumDebugPropertyInfo2::EnumChildren 에 대 한 관리 되는 코드에서 메서드의 지역 변수입니다.

namespace EEMC
{
    public class CEnumMethodField : IEnumDebugFields
    {
        public HRESULT Next(
                uint                  count,
                DEBUG_PROPERTY_INFO[] properties,
            out uint                  fetched)
        {
            if (count > properties.Length)
                throw new COMException();

            // Zero out the array.
            for (int i= 0; i < count; i++)
            {
                properties[i].bstrFullName = "";
                properties[i].bstrName = "";
                properties[i].bstrType = "";
                properties[i].bstrValue = "";
                properties[i].dwAttrib = 0;
                properties[i].dwFields = 0;
                properties[i].pProperty = null;
            }
            fetched = 0;

            // COM interop.
            HRESULT hr;
            uint innerFetched;
            IDebugField[] field = new IDebugField[1];

            while (fetched < count)
            {
                field[0] = null;
                innerFetched = 0;

                // Get next field.
                if (fetched < fieldCount)
                    hr = fields.Next(1, field, ref innerFetched);
                // No more fields.
                else return COM.S_FALSE;

                if (hr != COM.S_OK || innerFetched != 1 || field[0] == null)
                    throw new COMException("CEnumPropertyInfo.Next");

                // Get property from field.
                CFieldProperty fieldProperty = 
                    new CFieldProperty(provider, address, binder, field[0]);

                DEBUG_PROPERTY_INFO[] property =
                                new DEBUG_PROPERTY_INFO[1];
                fieldProperty.GetPropertyInfo((uint) infoFlags, radix, 0, null, 0, property);
                properties[fetched++] = property[0];
            }
            return COM.S_OK;
        }
    }
}

관리 되지 않는 코드

구현 하는이 예제를 보여 줍니다. IEnumDebugPropertyInfo2::EnumChildren 에 대 한 관리 되지 않는 코드에서 메서드의 지역 변수입니다.

STDMETHODIMP CEnumPropertyInfo::Next(
    in  ULONG                count,
    out DEBUG_PROPERTY_INFO* pelements, 
    out ULONG*               pfetched )
{
    if (pfetched)
        *pfetched = 0;
    if (!pelements)
        return E_INVALIDARG;
    else
        memset( pelements, 0, count * sizeof(DEBUG_PROPERTY_INFO));

    HRESULT hr  = S_OK;
    ULONG   idx = 0;
    while (idx < count)
    {
        ULONG        fetchedFields;
        IDebugField* pfield;

        //get the next field
        hr = m_fields->Next( 1, &pfield, &fetchedFields );
        if (FAILED(hr))
            return hr;
        if (fetchedFields != 1)
            return E_FAIL;
        idx++;

        //create a CFieldProperty to retrieve the DEBUG_PROPERTY_INFO
        CFieldProperty* pproperty =
            new CFieldProperty( m_provider, m_address, m_binder, pfield );
        pfield->Release();
        if (!pproperty)
            return E_OUTOFMEMORY;

        hr = pproperty->Init();
        if (FAILED(hr))
        {
            pproperty->Release();
            return hr;
        }

        hr = pproperty->GetPropertyInfo( m_infoFlags,
                                         m_radix,
                                         0,
                                         NULL,
                                         0,
                                         pelements + idx - 1);
        pproperty->Release();
        if (FAILED(hr))
            return hr;
    }

    if (pfetched)
        *pfetched = idx;
    return hr;
}

참고 항목

개념

지역 변수의 구현 샘플

지역 변수를 열거합니다.