Share via


Enumerating Objects

Use the IDirectMusicLoader8::EnumObject method to iterate through all objects of a specified class, or of all classes, that have previously been listed in the internal database through a call to IDirectMusicLoader8::ScanDirectory or calls to IDirectMusicLoader8::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. The loop continues until there are no more objects of that class to enumerate.

void ListStyles(IDirectMusicLoader *pILoader)
{
  if (pILoader)
  {
    HRESULT hr = pILoader->SetSearchDirectory(
        CLSID_DirectMusicStyle,
        L"c:\\mymusic",
        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 objDesc;
        objDesc.dwSize = sizeof(DMUS_OBJECTDESC);
        for (dwIndex = 0; ;dwIndex++)
        {
          if (S_OK ==(pILoader->EnumObject(
              CLSID_DirectMusicStyle,
              dwIndex, &objDesc)))
          {
             // Do something with information from objDesc.
            .
            .
            .
          }
          else break;
        }
      }
    }
  }
}

Notice that the 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 index number that is not valid.

© 2004 Microsoft Corporation. All rights reserved.