IDebugDocumentContext2::EnumCodeContexts
이 문서 컨텍스트와 연결된 모든 코드 컨텍스트의 목록을 검색합니다.
구문
매개 변수
ppEnumCodeCxts
\
Return Value
성공하면 S_OK
를 반환하고, 실패하면 오류 코드를 반환합니다.
설명
단일 문서 컨텍스트는 문서에서 템플릿을 사용하거나 파일을 포함할 때 여러 코드 컨텍스트를 생성할 수 있습니다.
예시
다음 예제에서는 IDebugDocumentContext2 인터페이스를 노출하는 간단한 CDebugContext
개체에 대해 이 메서드를 구현하는 방법을 보여 줍니다.
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;
}