Hi Brendan,
See the code below.
As I supposed the issue is that you have to use
Component2::GetChildren() instead of Component2::IGetChildren().
Regards
Andrey
void TraverseComponents(
IComponent2 *recComp, int
level)
{
typedef
IComponent2 *LPCOMPONENT2;
CComBSTR name, cfg;
int count
= 0;
recComp->IGetChildrenCount(&count);
if (
!count )
return;
LPDISPATCH*
componentChildrenArray;
VARIANT vChildren;
HRESULT hres = recComp->GetChildren(
&vChildren );
SAFEARRAY* psa = V_ARRAY(&vChildren);
HRESULT res = SafeArrayAccessData(psa,
(void
**)&componentChildrenArray);
long
highIndex;
SafeArrayGetUBound(psa, 1, &highIndex);
// Get index number of highest array
element
ASSERT ( count == ( highIndex + 1)
);
LPCOMPONENT2 m_childComponent =
NULL;
for(
int i = 0; i < count;
i++)
{
componentChildrenArray[i]->QueryInterface ( __uuidof(IComponent2), (void**)&m_childComponent );
if( m_childComponent != NULL)
{
componentChildrenArray[i]->AddRef();
for ( int i = 0; i < level; i++)
fprintf ( m_DebugFile, "\t" );
fprintf ( m_DebugFile,
"%d. ", level
);
m_childComponent->get_Name2 ( &name );
m_childComponent->get_ReferencedConfiguration ( &cfg );
fwprintf (m_DebugFile,
L" %s < %s >\n",
name, cfg );
TraverseComponents(
m_childComponent, level+1);
}
m_childComponent =
NULL;
}
hres = SafeArrayUnaccessData(psa);
// Unaccess the SafeArray
hres = SafeArrayDestroy(psa); // Destroy the SafeArray
}