DirectX SDK |
This topic pertains only to applications written in C++.
Sometimes it is desirable to tell the loader where to get an object, without actually loading that object, so that the loader can retrieve it if the object is later referred to by other objects as they are being loaded. You might also want to give an object a new attribute so that the loader can find it by that attribute.
The SetObject method takes as a parameter a DMUS_OBJECTDESC structure that contains two key pieces of information:
HRESULT SetObjectFromResource(const GUID* guid, int ID, char* type, WCHAR* name) { HRSRC hResource = NULL; HGLOBAL hData = NULL; hResource = FindResource(g_hInstance, MAKEINTRESOURCE(ID), type); if (hResource != NULL) { hData = LoadResource(g_hInstance, hResource); if (hData != NULL) { DMUS_OBJECTDESC desc; if(m_pLoader && (hResource != NULL) && (hData != NULL)) { ZeroMemory(&desc,sizeof(desc)); desc.pbMemData = (BYTE*) LockResource(*hData); desc.llMemLength = SizeofResource(g_hInstance, (*hResource)); desc.guidClass = (*guid); desc.dwSize = sizeof(desc); desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_MEMORY; if (name) { wcscpy(desc.wszName, name); desc.dwValidData |= DMUS_OBJ_NAME; } return m_pLoader->SetObject(&desc); } } } return E_FAIL; }
The following code could be used to assign a name to a MIDI file stored as a resource of type MIDI:
SetObjectFromResource(CLSID_DirectMusicSegment, 101, "MIDI", "canyon");
The object can now be loaded at any time by name.