By default, the loader looks for objects in the current directory, unless a full path is specified in the wszFileName member of the DMUS_OBJECTDESC structure describing the object being sought. By using the IDirectMusicLoader::SetSearchDirectory method, you can set a different default path for the IDirectMusicLoader::GetObject and IDirectMusicLoader::EnumObject methods. This default path can apply to all objects, or only objects of a certain class.
The following sample function sets the search path for style files:
HRESULT mySetLoaderPath (
IDirectMusicLoader *pILoader) // Previously created
{
return pILoader->SetSearchDirectory(
CLSID_DirectMusicStyle,
L"c:\\mymusic\\funky",
FALSE);
}
Having called this function, the application can now load a style by file name without including the full path, as in the following example function:
HRESULT myLoadStyleFromPath (
IDirectMusicStyle **ppIStyle, // Receives pointer to style
IDirectMusicLoader *pILoader) // Loader already created
{
HRESULT hr;
DMUS_OBJECTDESC Desc;
ZeroMemory(&Desc, sizeof(DMUS_OBJECTDESC);
Desc.dwSize = sizeof(DMUS_OBJECTDESC);
wcscpy(Desc.wszFileName, L"polka.sty"); // Short file name
Desc.guidClass = CLSID_DirectMusicStyle; // Object class
Desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
hr = pILoader->GetObject(&Desc,
IID_IDirectMusicStyle, (void **) ppIStyle);
return hr;
}