Udostępnij za pośrednictwem


IDebugDocumentContext2::EnumCodeContexts

Pobiera listę wszystkich kontekstów kodu skojarzonych z tym kontekstem dokumentu.

Składnia

int EnumCodeContexts(
    out IEnumDebugCodeContexts2 ppEnumCodeCxts
);

Parametry

ppEnumCodeCxts\

Wartość zwracana

Jeśli operacja powiedzie się, zwraca wartość S_OK; w przeciwnym razie zwraca kod błędu.

Uwagi

Pojedynczy kontekst dokumentu może generować wiele kontekstów kodu, gdy dokument korzysta z szablonów lub dołączania plików.

Przykład

W poniższym przykładzie pokazano, jak zaimplementować tę metodę dla prostego CDebugContext obiektu, który uwidacznia interfejs IDebugDocumentContext2 .

HRESULT CDebugContext::EnumCodeContexts(IEnumDebugCodeContexts2 **ppEnumCodeCxts)
{
    HRESULT hr;

    // Check for a valid IEnumDebugCodeContexts2 interface pointer.
    if (ppEnumCodeCxts)
    {
        *ppEnumCodeCxts = NULL;

        // Create a CEnumDebugCodeContexts object.
        CComObject<CEnumDebugCodeContexts>* pEnum;
        hr = CComObject<CEnumDebugCodeContexts>::CreateInstance(&pEnum);
        assert(hr == S_OK);
        if (hr == S_OK)
        {
            // Get an IID_IDebugCodeContext2 interface.
            CComPtr<IDebugCodeContext2> spCodeCxt;
            hr = QueryInterface(IID_IDebugCodeContext2,
                                (void**)&spCodeCxt);
            assert(hr == S_OK);
            if (hr == S_OK)
            {
                // Initialize the code context enumerator with the
                // IDebugCodeContext2 information.
                IDebugCodeContext2* rgpCodeContext[] = { spCodeCxt.p };
                hr = pEnum->Init(rgpCodeContext,
                                 &(rgpCodeContext[1]),
                                 NULL,
                                 AtlFlagCopy);
                assert(hr == S_OK);
                if (hr == S_OK)
                {
                // Set the passed IEnumDebugCodeContexts2 pointer equal to the pointer
                // value of the created CEnumDebugCodeContexts object.
                hr = pEnum->QueryInterface(ppEnumCodeCxts);
                assert(hr == S_OK);
                }
            }

            // Otherwise, delete the CEnumDebugCodeContexts object.
            if (FAILED(hr))
            {
                delete pEnum;
            }
        }
    }
    else
    {
        hr = E_INVALIDARG;
    }

    return hr;
}

Zobacz też