DirectX SDK

Enumerating Objects

[Visual Basic]

This topic pertains only to applications written in C++.

[C++]

Use the IDirectMusicLoader::EnumObject method to iterate through all objects of a given class, or of all classes, that have previously been listed in the internal database through a call to IDirectMusicLoader::ScanDirectory or calls to IDirectMusicLoader::GetObject. A description of each object found is returned in a DMUS_OBJECTDESC structure.

Note  To be sure of finding all objects, call ScanDirectory first. EnumObject works by checking the internal database of objects, not by parsing disk files.

The following example enumerates all listed style objects in the current search directory and displays information about each one by using the TRACE debugging macro. The loop continues until there are no more objects of that class to enumerate.

void myListStyles(
        IDirectMusicLoader *pILoader)
 
{
    HRESULT hr = pILoader->SetSearchDirectory(
            CLSID_DirectMusicStyle,
            L"c:\\mymusic\\wassup",
            TRUE);
    if (SUCCEEDED(hr))
    {
        hr = pILoader->ScanDirectory(
                CLSID_DirectMusicStyle,
                L"sty",
                L"stylecache");
        if (hr == S_OK)    // Only if files were found...
        {
            DWORD dwIndex;
            DMUS_OBJECTDESC Desc;
            Desc.dwSize = sizeof(DMUS_OBJECTDESC);
            for (dwIndex = 0; ;dwIndex++)
            {
                if (S_OK ==(pILoader->EnumObject(
                        CLSID_DirectMusicStyle,
                        dwIndex, &Desc)))
                {
                    TRACE("Name: %S, Category: %S, Path: %S\n",
                            Desc.wszName,
                            Desc.wszCategory,
                            Desc.wszFileName);
                }
                else break;
            }
        }
    }
}

This code example does not use the SUCCEEDED macro to test the result of the method call because EnumObject returns a success code, S_FALSE, for an invalid index number.