Platform SDK: DirectX

Step 3: Create the Loader

[Visual Basic]

This tutorial pertains only to applications written in C++. See DirectMusic Visual Basic Tutorials.

[C++]

In order to load any object from disk, you first need to create the DirectMusicLoader object. This is done just as for any other COM object, as shown in the following sample function:

IDirectMusicLoader* CreateLoader(void)
{
    IDirectMusicLoader* pLoader;
 
    if (FAILED(CoCreateInstance(
            CLSID_DirectMusicLoader,
            NULL,
            CLSCTX_INPROC, 
            IID_IDirectMusicLoader,
            (void**)&pLoader
        )))
    {
        pLoader = NULL;
    }
    return pLoader;
}
 

You'll use this function to initialize a global variable:

IDirectMusicLoader* g_pLoader = CreateLoader();
if (g_pLoader == NULL)
{
    // Failure -- loader not created
}

Next: Step 4: Load the MIDI File