Sometimes it is desirable to tell the loader where to get an object without actually loading that object, so that the loader will be able to retrieve it if the object is later referenced by other objects as they are being loaded.
For example, suppose your application uses its own DLS data for the General MIDI instrument collection. Normally, the loader finds Gm.dls at its default installation point and loads data from that file whenever an object is loaded that references the GM collection. In order to override that default behavior, before any of those referencing objects are loaded you need to tell the loader to get the collection from somewhere else. This is done by using the IDirectMusicLoader::SetObject method.
SetObject takes as a parameter a DMUS_OBJECTDESC structure that contains two key pieces of information:
The following sample code instructs the DirectMusicLoader m_pLoader to look for the GM collection in the file myGM.dls rather than in Gm.dls:
DMUS_OBJECTDESC ObjDesc;
wcscpy( ObjDesc.wszFileName,L"myGM.dls" );
ObjDesc.guidClass = CLSID_DirectMusicCollection;
ObjDesc.guidObject = GUID_DefaultGMCollection;
ObjDesc.dwSize = sizeof(DMUS_OBJECTDESC);
ObjDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME
| DMUS_OBJ_OBJECT;
HRESULT hr = m_pLoader->SetObject( &ObjDesc);
The following code forces the loader to look for the GM collection in a resource identified as IDR_GMDLS in the module hMod:
DMUS_OBJECTDESC ObjDesc;
HRSRC hFound = FindResource(hMod,
MAKEINTRESOURCE(IDR_GMDLS), RT_RCDATA);
HGLOBAL hRes = LoadResource(hMod, hFound);
ObjDesc.pbMemData = (BYTE *) LockResource(hRes);
ObjDesc.llMemLength = SizeofResource(hMod, hFound);
ObjDesc.guidClass = CLSID_DirectMusicCollection;
ObjDesc.guidObject = GUID_DefaultGMCollection;
ObjDesc.dwSize = sizeof(DMUS_OBJECTDESC);
ObjDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_MEMORY |
DMUS_OBJ_OBJECT;
HRESULT hr = m_pLoader->SetObject( &ObjDesc);